【问题标题】:Class name to table name ambiguity [duplicate]类名到表名歧义[重复]
【发布时间】:2015-07-23 09:07:08
【问题描述】:

我有一个已经存在的数据库转储。我想从那个垃圾场制作一个铁轨模型。我进行了数据库模式转储并从中进行了迁移。 我在数据库中的表名是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。请帮忙。

【问题讨论】:

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


    【解决方案1】:

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

    class PlanetOsmLine < ActiveRecord::Base
      self.table_name = "planet_osm_line"
    end
    

    【讨论】:

    • 成功了!谢谢。
    猜你喜欢
    • 2017-08-26
    • 2019-06-13
    • 1970-01-01
    • 2018-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-04
    相关资源
    最近更新 更多