hee guys.. I have a problem with HABTM... I have articles en users... wich are connected to rights... beceause users can have more then 1 right and rights can have more than one user... and the same by articles of course I have 3 models: the user: has_and_belongs_to_many :rights the article: has_and_belongs_to_many :rights and rights: has_and_belongs_to_many :users has_and_belongs_to_many :articles and 2 join tables. I have a user_id and I want to list all the articles which he has access to: @user = User.find_by_id(2) @right = @user.rights @article_list= @right.articles but this doesn''t work... Does anyone now how to get multiple articles from one user ? -- 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 -~----------~----~----~----~------~----~------~--~---
julien.guimont-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Nov-05 13:57 UTC
Re: multiple HABTM ..
Hello, You are actually getting a array of rights from this: @right = @user.rights So not a right per se. You should call @right.articles on a Right object... Julien. On Nov 4, 4:00 pm, Heldop Slippers <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> hee guys.. > > I have a problem with HABTM... > I have articles en users... wich are connected to rights... beceause > users can have more then 1 right and rights can have more than one > user... and the same by articles of course > > I have 3 models: > > the user: has_and_belongs_to_many :rights > the article: has_and_belongs_to_many :rights > > and rights: has_and_belongs_to_many :users > has_and_belongs_to_many :articles > > and 2 join tables. > > I have a user_id and I want to list all the articles which he has access > to: > @user = User.find_by_id(2) > @right = @user.rights > @article_list= @right.articles > > but this doesn''t work... Does anyone now how to get multiple articles > from one user ? > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
julien.guimont-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Hello, > > You are actually getting a array of rights from this: > @right = @user.rights > > So not a right per se. You should call @right.articles on a Right > object... > > Julien. > > On Nov 4, 4:00 pm, Heldop Slippers <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Thanxs for the response Julien !! Hmmm I think I dont understand it quit well ... is tryed a few things... @right = User.find_by_id(1) @article_list= @right.articles and tryed: @right = User.find_by_id(1) @article = @right.articles @article_list= @articles.articles and: @right = User.find_by_id(1) @article_list = @right.articles.rights but it all doens''t work :( I hope someone can tell wat I do wrong... -- 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 -~----------~----~----~----~------~----~------~--~---
Heldop Slippers wrote:> julien.guimont-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: >> Hello, >> >> You are actually getting a array of rights from this: >> @right = @user.rights >> >> So not a right per se. You should call @right.articles on a Right >> object... >> >> Julien. >> >> On Nov 4, 4:00 pm, Heldop Slippers <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > > Thanxs for the response Julien !! > Hmmm I think I dont understand it quit well ... > > > is tryed a few things... > > @right = User.find_by_id(1) > @article_list= @right.articles > > > and tryed: > > @right = User.find_by_id(1) > @article = @right.articles > @article_list= @articles.articles > > and: > > @right = User.find_by_id(1) > @article_list = @right.articles.rights > > > but it all doens''t work :( > I hope someone can tell wat I do wrong...a little update... If i say that right_id is 1 than it does work.. @right = Right.find(1) @article_list = @right.articles but if I do: @right = Right.find(:all) @article_list = @right.articles so I want to select all the right ID''s and have there the articles from it is comming with an error: undefined method `articles'' I hope someone can help me -- 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 -~----------~----~----~----~------~----~------~--~---