Relations between same class objects

I’m having a problem mapping relations between classes representing
different roles.

For instance, let’s assume a social network. A user can relate to other
users thought a friendship relation. So I would like to have a table
names friends that would have user1_id and user2_id and some more
attributes. Rails would requires something like a many to many relation
with a table users_users with two columns: user_id and user_id. Of
course this doesn’t make sense. I know how to hack this but I would like
to know what’s “the ruby way” for this, using simple active records
relations.

Thanks

Here’s the best explanation of self-referential associations:

http://blog.hasmanythrough.com/articles/2006/04/21/self-referential-through

Scroll down to the comments and you’ll see how it translates to a
“friends” situation

Chad wrote:

Here’s the best explanation of self-referential associations:

http://blog.hasmanythrough.com/articles/2006/04/21/self-referential-through

Scroll down to the comments and you’ll see how it translates to a
“friends” situation

This is perfect. Thanks.

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