Forum: Ruby on Rails need some info regarding "how to add friends"

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ec66b8181d0cefdb85e32928216cc0ff?d=identicon&s=25 gow (Guest)
on 2007-06-28 08:07
(Received via mailing list)
hi every one,

i'm new to ruby on, need some help.

my project is that a user can add friends to his profile where friends
are users themselves.

i thought of creating two tables one for users and other for
user_friends.i don't know how to relate these two tables so that they
serve my purpose.

any suggestions plz.

thanks in advance.
3e16f7851a2198a1f8718855a0d2abb3?d=identicon&s=25 RussianGeek (Guest)
on 2007-06-28 08:50
(Received via mailing list)
I am also new but I think you just need to add to Users model:
has_and_belongs_to_many :users.
4c3acdc3d93f54cc7a7281780ec8a4ee?d=identicon&s=25 Shai Rosenfeld (shai)
on 2007-06-28 09:51
check out self referential associations - it is exactly what you are
looking for.
the problem with doing has_and_belongs_to_many :users, is that you will
still need a join table that 'holds' these associated records.

give it time, it looks daunting at first, but it works. :)
a couple links:

i worked with this
although it is clearly outdated, and there are probably better things
out there.
i also googled for a sec, and found
     (same plugin)

anyway .. check out google for self_referential; that's the way to go.
hope this helps!

Ec66b8181d0cefdb85e32928216cc0ff?d=identicon&s=25 gow (Guest)
on 2007-06-29 06:04
(Received via mailing list)
thank u russian for the reply.

i did add has_and_belongs_to_many :users. to User model.
Ec66b8181d0cefdb85e32928216cc0ff?d=identicon&s=25 gow (Guest)
on 2007-06-29 06:08
(Received via mailing list)
thank u shai

the urls u send were really helpful.i got great deal of relevant stuff
from those links.

On Jun 28, 12:51 pm, Shai Rosenfeld <>
This topic is locked and can not be replied to.