0
有两种型号:Rails的:找到制约态关联
User has_one :location, as: locatable
Location belongs_to :locatable, polymorphic: true
到目前为止好。现在说我要找到一个特定的名称和城市用户:
User.joins(:location).where(name: 'Eddie Explosion', location: { city: 'Kaboom' })
...但是当我运行,咚,
ActiveRecord::StatementInvalid: PG::Error: ERROR: missing FROM-clause entry for table "location".
任何想法是怎么回事/如何解决这个?似乎无法弄清楚。
工作,谢谢。它归结为使用“位置”而不是“位置”。如果它可以帮助任何人,你也可以这样做:User.joins(:location).where(name:'Eddie Explosion',locations:{city:'Kaboom'}) – fedenusy