Active record confusion

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

This may be what you are after

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

-Peter

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs