类名称与表名歧义

时间:2015-07-23 09:07:08

标签: ruby-on-rails ruby-on-rails-3 postgresql ruby-on-rails-4

我有一个已经存在的数据库转储。我想从那个转储中为rails做一个模型。我采用了数据库模式转储并从中进行了迁移。 我在数据库中的表名是planet_osm_line,各自的模型是planet_osm_line.rb 模型中的代码是

    class PlanetOsmLine < ActiveRecord::Base
    end

当我执行此查询时,现在在rails控制台中玩游戏

PlanetOsmLine.where("name ilike '%salvi%'")

它在planet_osm_lines中搜索。如何让它引用planet_osm_line而不是planet_osm_lines。请帮忙。

1 个答案:

答案 0 :(得分:0)

使用self.table_name分配自定义表名

class PlanetOsmLine < ActiveRecord::Base
  self.table_name = "planet_osm_line"
end
相关问题