I have three models. Admin, Stuff, Permission. Each admin can do lots of stuff, but only if they have permission. I have the following relationship set up: class Admin has_many :stuffs, :through => :permissions end class Stuff has_many :admins, :through => :permissions end class Permission belongs_to :admin belongs_to :stuff end I want to be able to see the permissions an admin has so I call: admin.stuff and expect an array of stuff they have permission to. Am I completely missing the boat here? Thanks, Bryce --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
David A. Black
2007-Apr-20 21:19 UTC
Re: has_many :through ... am I missing something here?
Hi -- On 4/20/07, Bryce <brycebrycebaby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I have three models. Admin, Stuff, Permission. > > Each admin can do lots of stuff, but only if they have permission. I > have the following relationship set up: > > class Admin > has_many :stuffs, :through => :permissions > end > > class Stuff > has_many :admins, :through => :permissions > end > > class Permission > belongs_to :admin > belongs_to :stuff > end > > I want to be able to see the permissions an admin has so I call: > admin.stuff and expect an array of stuff they have permission to. Am > I completely missing the boat here?You need to make sure that Admin and Stuff each has_many :permisisons. Otherwise there''s nothing for them to have_many of each other :through. Then call: admin.stuff David -- Upcoming Rails training by Ruby Power and Light: Four-day Intro to Intermediate May 8-11, 2007 Edison, NJ http://www.rubypal.com/events/05082007 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Duh. Thanks a lot. That helped get me out of a rut. Bryce On Apr 20, 2:19 pm, "David A. Black" <dbl...-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org> wrote:> Hi -- > > On 4/20/07, Bryce <brycebryceb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > I have three models. Admin, Stuff, Permission. > > > Each admin can do lots of stuff, but only if they have permission. I > > have the following relationship set up: > > > class Admin > > has_many :stuffs, :through => :permissions > > end > > > class Stuff > > has_many :admins, :through => :permissions > > end > > > class Permission > > belongs_to :admin > > belongs_to :stuff > > end > > > I want to be able to see the permissions an admin has so I call: > > admin.stuff and expect an array of stuff they have permission to. Am > > I completely missing the boat here? > > You need to make sure that Admin and Stuff each has_many :permisisons. > Otherwise there''s nothing for them to have_many of each other > :through. > > Then call: > > admin.stuff > > David > > -- > Upcoming Rails training by Ruby Power and Light: > Four-day Intro to Intermediate > May 8-11, 2007 > Edison, NJ > http://www.rubypal.com/events/05082007--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
David A. Black
2007-Apr-20 22:53 UTC
Re: has_many :through ... am I missing something here?
Hi --> > Then call: > > > > admin.stuffWhoops, I meant admin.stuffs. I was thinking it but I guess my fingers just refused to type it :-) David -- Upcoming Rails training by Ruby Power and Light: Four-day Intro to Intermediate May 8-11, 2007 Edison, NJ http://www.rubypal.com/events/05082007 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---