J'ai un modèle Product
, je veux mettre en œuvre l'auto-association sur ces deux champs channel_advisor_product_id
, parent_product_id
. Mais quand je l'appelle Product.last.child_products
il prend son id
au lieu de parent_product_id
Ajouter auto-un-à-plusieurs association en utilisant d'autres champs, sauf 'id'
belongs_to :parent_product, class_name: 'Product', primary_key: "channel_advisor_product_id"
has_many :child_products, class_name: 'Product', foreign_key: "parent_product_id"