What To Do When You Have A Relationship Between Two Objects

Lets say user1 is friends with user2 where user one is a relationship
table. How do you connect two users on the same id i.e. user_id?

user_id → friends with → user_id

friends table

user_id | user_id | description | created_at | updated_at

We can’t have two user_id’s so any suggestions how can I do this?

Thanks for your help! :slight_smile:


John K.
[email protected]

http://www.kopanas.com

http://www.soen.info

Hello John,

2006/10/31, John K. [email protected]:

We can’t have two user_id’s so any suggestions how can I do this?

Nothing prevents you from naming one of the foreign key “friend_id”,
right ? And from there, belongs_to / has_many have a :foreign_key
option which tell it the name of the foreign key.

Hope that helps !

François Beausoleil
http://blog.teksol.info/
http://piston.rubyforge.org/