Rails Polymorphic Association with multiple associations on the same model

后端 未结 10 1887
无人及你
无人及你 2020-11-28 03:01

My question is essentially the same as this one: Polymorphic Association with multiple associations on the same model

However, the proposed/accepted solution does no

10条回答
  •  無奈伤痛
    2020-11-28 03:56

    Something like following worked for querying, but assigning from User to address didn't work

    User Class

    has_many :addresses, as: :address_holder
    has_many :delivery_addresses, -> { where :address_holder_type => "UserDelivery" },
           class_name: "Address", foreign_key: "address_holder_id"
    

    Address Class

    belongs_to :address_holder, polymorphic: true
    

提交回复
热议问题