Answers for "eager load polymorphic rails"

1

eager load polymorphic rails

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
Posted by: Guest on November-02-2021

Browse Popular Code Answers by Language