Class 名字到 table 名字歧义
Class name to table name ambiguity
我有一个已经存在的数据库转储。我想从那个转储中为 rails 制作一个模型。我获取了一个数据库模式转储并从中进行了迁移。
我的 table 在数据库中的名字是 planet_osm_line,相应的型号是 planet_osm_line.rb
模型中的代码是
class PlanetOsmLine < ActiveRecord::Base
end
当我执行此查询时,现在在 rails 控制台中运行
PlanetOsmLine.where("name ilike '%salvi%'")
它在 planet_osm_line 秒内搜索。我如何让它引用 planet_osm_line 而不是 planet_osm_lines。请帮忙。
使用self.table_name
分配自定义table名称
class PlanetOsmLine < ActiveRecord::Base
self.table_name = "planet_osm_line"
end
我有一个已经存在的数据库转储。我想从那个转储中为 rails 制作一个模型。我获取了一个数据库模式转储并从中进行了迁移。 我的 table 在数据库中的名字是 planet_osm_line,相应的型号是 planet_osm_line.rb 模型中的代码是
class PlanetOsmLine < ActiveRecord::Base
end
当我执行此查询时,现在在 rails 控制台中运行
PlanetOsmLine.where("name ilike '%salvi%'")
它在 planet_osm_line 秒内搜索。我如何让它引用 planet_osm_line 而不是 planet_osm_lines。请帮忙。
使用self.table_name
分配自定义table名称
class PlanetOsmLine < ActiveRecord::Base
self.table_name = "planet_osm_line"
end