Hi, how do i do a relation for my users table ? The problem is following: im building community site, where are users. every user can have a friend which is user too. so i created migration which adds to my users table new column user_id, and i also addes has_many relationship to User model. so i want that both of them have reference to each other, they are friends right ? im not sure if i have to user belongs_to too... 1. is this ok ? 2. i dont want to use syntax like: user.users, but rather user.friends... how do i do this ? in rails im forced to create user_id column which is accesible through users property in my user model, this is convenction over cofiguration and i dont like it in this particular situation. thanks in advance regards --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Piotr Nowak wrote:> how do i do a relation for my users table ? > The problem is following: > > im building community site, where are users. every user can have a > friend which is user too. > so i created migration which adds to my users table new column user_id, > and i also addes has_many relationship to User model. > > so i want that both of them have reference to each other, they are > friends right ? im not sure if i have to user belongs_to too... > > 1. is this ok ? > 2. i dont want to use syntax like: user.users, but rather > user.friends...You''ll need a self-referential has_many :through setup. I cover how to do it here: http://blog.hasmanythrough.com/2007/10/30/self-referential-has-many-through> how do i do this ? in rails im forced to create user_id column which is > accesible through users property in my user model, this is convenction > over cofiguration and i dont like it in this particular situation.There are very few conventions in Rails that are forced on you. Keep reading up and you''ll see how to configure things to work differently when you need to. -- Josh Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---