# Has\_many :through ... am I missing something here?

**URL:** <https://www.ruby-forum.com/t/has-many-through-am-i-missing-something-here/92577>\
**Category:** Rails\
**Created:** [April 20, 2007, 11:00pm UTC](https://www.ruby-forum.com/t/has-many-through-am-i-missing-something-here/92577 "2007-04-20T23:00:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bryce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8edcca/32.png) [@Bryce](https://www.ruby-forum.com/u/Bryce)\
**Post date:** [April 20, 2007, 11:00pm UTC](https://www.ruby-forum.com/t/has-many-through-am-i-missing-something-here/92577/1 "2007-04-20T23:00:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Bryce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8edcca/32.png) [@Bryce](https://www.ruby-forum.com/u/Bryce)\
**Post date:** [April 20, 2007, 11:20pm UTC](https://www.ruby-forum.com/t/has-many-through-am-i-missing-something-here/92577/2 "2007-04-20T23:20:09Z")

</div>

Hi –

On 4/20/07, Bryce [removed\_email\_address@domain.invalid](mailto: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](http://www.rubypal.com/events/05082007)

---

<div class="post-metadata">

**Author:** ![Bryce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8edcca/32.png) [@Bryce](https://www.ruby-forum.com/u/Bryce)\
**Post date:** [April 20, 2007, 11:36pm UTC](https://www.ruby-forum.com/t/has-many-through-am-i-missing-something-here/92577/3 "2007-04-20T23:36:10Z")

</div>

Duh.

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

Bryce

---

<div class="post-metadata">

**Author:** ![Bryce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8edcca/32.png) [@Bryce](https://www.ruby-forum.com/u/Bryce)\
**Post date:** [April 21, 2007, 12:55am UTC](https://www.ruby-forum.com/t/has-many-through-am-i-missing-something-here/92577/4 "2007-04-21T00:55:16Z")

</div>

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](http://www.rubypal.com/events/05082007)
