has_many :through with class_name and foreign_key

后端 未结 3 2027
迷失自我
迷失自我 2020-12-24 01:06

I\'m working with a fairly straightforward has_many through: situation where I can make the class_name/foreign_key parameters work in one direction but not the other. Perhap

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-24 01:40

    i had several issues with my models, had to add the foreign key as well as the source and class name... this was the only workaround i found:

      has_many :ticket_purchase_details, foreign_key: :ticket_purchase_id, source: :ticket_purchase_details, class_name: 'TicketPurchaseDetail'
    
      has_many :details, through: :ticket_purchase_details, source: :ticket_purchase, class_name: 'TicketPurchaseDetail'
    

提交回复
热议问题