'Ho to add include polymorphic association to nested association
I have a model with a polymorphic association :
class Poi < ApplicationRecord
belongs_to :poitable, polymorphic: true, optional: true, dependent: :destroy, touch: true
belongs_to :master_poi, class_name: 'Poi', optional: true
end
class Course < ApplicationRecord
belongs_to :poi_start, optional: true, class_name: 'Poi'
belongs_to :poi_end, optional: true, class_name: 'Poi'.
has_many :steps, -> { includes(:poi_start, poi_end: [:services, master_poi: [:services] ])
end
poi_start, poi_end, master_poi are attached to Poi model
I would like to add poitable association to the has_many :steps like :
has_many :steps, -> { includes(:poi_start, poi_end: [:poitable, :services, master_poi: [:poitable, :services] ])
but get an error "Cannot eagerly load the polymorphic association :poitable"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
