Forum: Ruby on Rails Two foreign keys to the same table

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C7d5bc5b054035d95f287797c2595694?d=identicon&s=25 Matias (Guest)
on 2006-02-02 11:03
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.
C7669e8b5676f61fdf202230cbcf72d8?d=identicon&s=25 Mikkel Bruun (mikkel)
on 2006-02-02 11:25
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/As...
This topic is locked and can not be replied to.