Active record confusion


#1

Hi,

I’m trying to setup an application where users are interconnected.

For example, each user will have multiple friends and each user can be
friend of multiple people. Now, I just have one User table with fields (
id, name, information ). How do I use ActiveRecord in such a way that I
get all friends of a perticular user by giving User.find(1).friends ?

Thanks a lot,
Pratik


#2

This may be what you are after

http://wiki.rubyonrails.com/rails/pages/HowToCreateASelfReferentialManyToManyRelationship

-Peter


#3

Thanks a lot Peter ! That what exactly what I was looking for :slight_smile:

Cheers,
Pratik

Peter M. wrote:

This may be what you are after

http://wiki.rubyonrails.com/rails/pages/HowToCreateASelfReferentialManyToManyRelationship

-Peter


#4

Thanks a lot Peter ! That’s exactly what I was looking for :slight_smile:

Cheers,
Pratik

Peter M. wrote:

This may be what you are after

http://wiki.rubyonrails.com/rails/pages/HowToCreateASelfReferentialManyToManyRelationship

-Peter