PLEASE HELP! REMOVE DUPLICATE STATUS!
I know this was marked as a duplicate, but I do not think the other postings address my issue, please help explain what I am missing or address my current issue.
Thank you!
SOLUTION NOT RESOLVED FROM OTHER POSTINGS
Based on this Eager load polymorphic I tried
Listing Model
belongs_to :listable, polymorphic: true
belongs_to :car, foreign_type: 'Car', foreign_key: 'listable_id'
belongs_to :truck, foreign_type: 'Truck', foreign_key: 'listable_id'
belongs_to :bike, foreign_type: 'Bike', foreign_key: 'listable_id'
AND TRIED:
Listing Model
belongs_to :listable, polymorphic: true
belongs_to :car, -> { where(listings: {listable_type: 'Car'}) }, foreign_key: 'listable_id'
But got the same error!
This post shows that it should work: https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Eager+loading+of+associations
But it does not.
ORIGINAL POST:
Need to query all listings that belong to a user in Rails 5.2.
I have read many other posts, but do not see how they apply to this issue.
I tried
Listing.includes(listable:[:user]).where('users.id': 100)
But I get
ActiveRecord::EagerLoadPolymorphicError (Cannot eagerly load the polymorphic association :listable)
User Model
User has_one Car
User has_one Truck
User has_one Bike
Car Model
belongs_to :user
has_one :listing, as: :listable
Truck Model
belongs_to :user
has_one :listing, as: :listable
Bike Model
belongs_to :user
has_one :listing, as: :listable
Listing Model
belongs_to :listable, polymorphic: true