I''m curious what would be the best way to represent people and whether the person has someone marked as their friend. Here are my thoughts so far: People table - id - name Relationships table - person_id - friend_id Now my problem is I don''t know how to set up these associations (if this is even correct). Friend_id would be an id to someone else from the people table. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060528/7687ace3/attachment.html
I''m curious what would be the best way to represent people and whether the person has someone marked as their friend. Here are my thoughts so far: People table - id - name Relationships table - person_id - friend_id Now my problem is I don''t know how to set up these associations (if this is even correct). Friend_id would be an id to someone else from the people table. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060528/34c5368a/attachment.html
You should check out the rails book Section 15.3 Single table inheritance _____ From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Davy Campano Sent: Sunday, May 28, 2006 10:11 AM To: rails@lists.rubyonrails.org Subject: [Rails] Association of table to itself I''m curious what would be the best way to represent people and whether the person has someone marked as their friend. Here are my thoughts so far: People table - id - name Relationships table - person_id - friend_id Now my problem is I don''t know how to set up these associations (if this is even correct). Friend_id would be an id to someone else from the people table. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060528/b669a64e/attachment.html
Davy Campano wrote:> I''m curious what would be the best way to represent people and whether the > person has someone marked as their friend. Here are my thoughts so far: > > People table > - id > - name > > > Relationships table > - person_id > - friend_id > > Now my problem is I don''t know how to set up these associations (if this is > even correct). Friend_id would be an id to someone else from the people table.You can do this with a self-referential has_many :through association. http://blog.hasmanythrough.com/articles/2006/04/21/self-referential-through -- Josh Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/.