Two models:
User has_one :location, as: locatable
Location belongs_to :locatable, polymorphic: true
So far so good. Now say I want to find a User with a certain name and city:
User.joins(:location).where(name: 'Eddie Explosion', location: { city: 'Kaboom' })
…but when I run that, boom,
ActiveRecord::StatementInvalid: PG::Error: ERROR: missing FROM-clause entry for table “location”.
Any idea what’s going on here / how to fix this? Can’t seem to figure it out.
I can’t really experiment on the exact case you have, but I have done something similar to what you want to do in my application, here is an example below:
Cheers :))