Two foreign keys to the same table

Hi,

I’ve two tables:

ProductLists (id, name, …)
Product (id,name,product_list_1_id, product_list_2_id, …)

How can I map the fields product_list_1_id and product_list_2_id to the
ProductLists table in activerecord???

Thanks.

Matias wrote:

Hi,

I’ve two tables:

ProductLists (id, name, …)
Product (id,name,product_list_1_id, product_list_2_id, …)

How can I map the fields product_list_1_id and product_list_2_id to the
ProductLists table in activerecord???

Thanks.

class Product < blabla
belongs_to
:list1,:class_name=>“ProductList”,:foreign_key=>“product_list_1_id”
belongs_to
:list2,:class_name=>“ProductList”,:foreign_key=>“product_list_2_id”

end

http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#M000473

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs