Eager Load Polymorphic Rails

[Solved] Eager Load Polymorphic Rails | Ruby - Code Explorer | yomemimo.com
Question : eager load polymorphic rails

Answered by : mo-lucas

You need to add a custom belongs_to to your polymorphic model
class Shipment has_many :payments, as: :paymentable
end
class Payment belongs_to :paymentable, polymorphic: true # Add a custom belongs_to that points to Shipment belongs_to :shipment, foreign_type: 'Shipment', foreign_key: 'paymentable_id'
end

Source : | Last Update : Tue, 09 Nov 21

Answers related to eager load polymorphic rails

Code Explorer Popular Question For Ruby