Although risking a stupid question, I have the following "challenge":
In
a simple community portal users have some sort of "is-contact-of"
relation to other users.
I planned to model this by
class User
has_and_belongs_to :users
end
which of course doesn''t work, because the join table
create table users_users (
user_id int not null,
user_id int not null,
foreign key (user_id) references users (id),
foreign key (user_id) references users (id),
primary key (user_id, user_id)
) type = InnoDB, character set utf8;
cannot be created in MySQL.
How would I model that best?
Starburger
--
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
-~----------~----~----~----~------~----~------~--~---
On 2/1/07, starburger <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Although risking a stupid question, I have the following "challenge": In > a simple community portal users have some sort of "is-contact-of" > relation to other users. > > I planned to model this by > > class User > has_and_belongs_to :users > end > > which of course doesn''t work, because the join table > > create table users_users ( > user_id int not null, > user_id int not null, > > foreign key (user_id) references users (id), > foreign key (user_id) references users (id), > primary key (user_id, user_id) > ) type = InnoDB, character set utf8; > > cannot be created in MySQL. > > How would I model that best? > > StarburgerUse a join table Contacts with user_id and contact_id fields. Then use a has_many :through association to find a user''s contacts. Also, check out this post and the comments that follow: http://blog.hasmanythrough.com/2006/4/21/self-referential-through Hope this helps, -- Zack Chandler http://depixelate.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 -~----------~----~----~----~------~----~------~--~---
Zack Chandler wrote:> On 2/1/07, starburger <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> >> cannot be created in MySQL. >> >> How would I model that best? >> >> Starburger > > Use a join table Contacts with user_id and contact_id fields. Then > use a has_many :through association to find a user''s contacts. > > Also, check out this post and the comments that follow: > http://blog.hasmanythrough.com/2006/4/21/self-referential-through > > Hope this helps, > > -- > Zack Chandler > http://depixelate.comThanks. That helped. A detailleed example for self-referential has_many can be found at http://www.aldenta.com/2006/11/10/has_many-through-self-referential-example/ Starburger -- 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 -~----------~----~----~----~------~----~------~--~---