📜  急切加载多态导轨 - Ruby 代码示例

📅  最后修改于: 2022-03-11 15:04:45.685000             🧑  作者: Mango

代码示例1
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