# Social graph

**URL:** <https://www.ruby-forum.com/t/social-graph/131514>\
**Category:** Rails\
**Created:** [March 10, 2008, 9:47pm UTC](https://www.ruby-forum.com/t/social-graph/131514 "2008-03-10T21:47:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gadys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@gadys](https://www.ruby-forum.com/u/gadys)\
**Post date:** [March 10, 2008, 9:47pm UTC](https://www.ruby-forum.com/t/social-graph/131514/1 "2008-03-10T21:47:40Z")

</div>

Hi  
I’m trying to build a new facebook app.  
I want to keep a database of the friends of friends for each user.  
what’s the best way to store and maintain such a graph ?

thanks  
Gady

---

<div class="post-metadata">

**Author:** ![gadys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@gadys](https://www.ruby-forum.com/u/gadys)\
**Post date:** [March 10, 2008, 10:00pm UTC](https://www.ruby-forum.com/t/social-graph/131514/2 "2008-03-10T22:00:27Z")

</div>

Hi Gady,

There was an interesting article in February’s edition on Linux  
Journal (166) about Rails and Facebook API integration.  
[http://www.linuxjournal.com/article/9924](http://www.linuxjournal.com/article/9924)

They suggested a few of resources  
[http://wiki.developers.facebook.com/index.php/Using\_Ruby\_on\_Rails\_with\_Facebook\_Platform](http://wiki.developers.facebook.com/index.php/Using_Ruby_on_Rails_with_Facebook_Platform)  
[http://rfacebook.rubyforge.org/](http://rfacebook.rubyforge.org/)  
[http://www.chadfowler.com/2007/9/5/writing-apis-to-wrap-apis](http://www.chadfowler.com/2007/9/5/writing-apis-to-wrap-apis)

Cheers,  
Ewan

---

<div class="post-metadata">

**Author:** ![gadys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@gadys](https://www.ruby-forum.com/u/gadys)\
**Post date:** [March 10, 2008, 10:19pm UTC](https://www.ruby-forum.com/t/social-graph/131514/3 "2008-03-10T22:19:29Z")

</div>

Gady S. wrote:

> Hi  
> I’m trying to build a new facebook app.  
> I want to keep a database of the friends of friends for each user.  
> what’s the best way to store and maintain such a graph ?

I imagine if you have a table of just the friends of each user (columns:  
user\_id, friend\_user\_id), you can get the collection of friends of  
friends of each user.

Something like:

select  
u.\*  
from  
user u,  
friends f1,  
friends f2  
where  
f2.user\_id = :given\_user\_id and  
f2.friend\_user\_id = f1.user\_id and  
f1.friend\_user\_id = u.id and

Stephan
