Forum: Ruby on Rails has_many :through ... am I missing something here?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bryce (Guest)
on 2007-04-21 01:00
(Received via mailing list)
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
David A. Black (Guest)
on 2007-04-21 01:20
(Received via mailing list)
Hi --

On 4/20/07, Bryce <removed_email_address@domain.invalid> wrote:
> class Stuff
> 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
Bryce (Guest)
on 2007-04-21 01:36
(Received via mailing list)
Duh.

Thanks a lot. That helped get me out of a rut.

Bryce
David A. Black (Guest)
on 2007-04-21 02:55
(Received via mailing list)
Hi --

> > Then call:
> >
> >   admin.stuff

Whoops, 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
This topic is locked and can not be replied to.