# Best way to implement friendship thing?

**URL:** <https://www.ruby-forum.com/t/best-way-to-implement-friendship-thing/127729>\
**Category:** Rails\
**Created:** [January 31, 2008, 8:11pm UTC](https://www.ruby-forum.com/t/best-way-to-implement-friendship-thing/127729 "2008-01-31T20:11:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [January 31, 2008, 8:11pm UTC](https://www.ruby-forum.com/t/best-way-to-implement-friendship-thing/127729/1 "2008-01-31T20:11:40Z")

</div>

I am new to rails and have to develop a small app which will do regular  
social networking.  
So, whats the best and efficient way to implement friends/friendship  
thing so that I could get complete list of every user’s friends with  
@user.friends and also which is easy to maintain and implement.

Thanks.

---

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [January 31, 2008, 8:17pm UTC](https://www.ruby-forum.com/t/best-way-to-implement-friendship-thing/127729/2 "2008-01-31T20:17:13Z")

</div>

Vapor … wrote:

> I am new to rails and have to develop a small app which will do regular  
> social networking.  
> So, whats the best and efficient way to implement friends/friendship  
> thing so that I could get complete list of every user’s friends with  
> @user.friends and also which is easy to maintain and implement.
> 
> Thanks.

You’ll want to do a self referential ‘has\_many :through =\>’.

A google search with just the right keywords (eg: self referential  
has\_many through) should get you all the information you need, and then  
some.

Good Luck! And welcome to Rails.

–  
[http://www.5valleys.com/](http://www.5valleys.com/)  
[http://www.workingwithrails.com/person/8078](http://www.workingwithrails.com/person/8078)

---

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [January 31, 2008, 11:10pm UTC](https://www.ruby-forum.com/t/best-way-to-implement-friendship-thing/127729/3 "2008-01-31T23:10:25Z")

</div>

Hi Jon,

Take a look at this plugin.  
[http://www.railslodge.com/plugins/40-has-many-friends](http://www.railslodge.com/plugins/40-has-many-friends)

Jon G. wrote:

> Vapor … wrote:
> 
> > I am new to rails and have to develop a small app which will do regular  
> > social networking.  
> > So, whats the best and efficient way to implement friends/friendship  
> > thing so that I could get complete list of every user’s friends with  
> > @user.friends and also which is easy to maintain and implement.

---

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [February 1, 2008, 6:15am UTC](https://www.ruby-forum.com/t/best-way-to-implement-friendship-thing/127729/4 "2008-02-01T06:15:36Z")

</div>

Scott A S wrote:

> Hi Jon,
> 
> Take a look at this plugin.  
> [http://www.railslodge.com/plugins/40-has-many-friends](http://www.railslodge.com/plugins/40-has-many-friends)

actually I want to sort of understand it…I mean how it all actually  
works with has\_many =\> :through

---

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [January 31, 2008, 8:27pm UTC](https://www.ruby-forum.com/t/best-way-to-implement-friendship-thing/127729/5 "2008-01-31T20:27:44Z")

</div>

Use the awesome plugin “has\_many\_friends”:  
[http://svn.dnite.org/has\_many\_friends/README](http://svn.dnite.org/has_many_friends/README)

---

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [February 1, 2008, 8:02pm UTC](https://www.ruby-forum.com/t/best-way-to-implement-friendship-thing/127729/6 "2008-02-01T20:02:44Z")

</div>

Check out RailsSpace book on Amazon:  
[http://www.amazon.com/RailsSpace-Building-Networking-Addison-Wesley-Professional/dp/0321480791/ref=pd\_bbs\_sr\_1?ie=UTF8&s=books&qid=1201892461&sr=1-1](http://www.amazon.com/RailsSpace-Building-Networking-Addison-Wesley-Professional/dp/0321480791/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1201892461&sr=1-1)

---

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [February 1, 2008, 2:12pm UTC](https://www.ruby-forum.com/t/best-way-to-implement-friendship-thing/127729/7 "2008-02-01T14:12:45Z")

</div>

The post I liked the most is:

[http://www.fallenrogue.com/article/view/143-I-am-what-I-am-or-self-referential-joins-in-Rails](http://www.fallenrogue.com/article/view/143-I-am-what-I-am-or-self-referential-joins-in-Rails)

AWDWR and Rails Recipes also help a lot.

Cheers, Sazima

On Feb 1, 3:15 am, “Vapor …” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
