# can access the through attributes from the many with has\_many 	through?

**URL:** <https://discuss.rubyonrails.org/t/can-access-the-through-attributes-from-the-many-with-has-many-through/51558>\
**Category:** rubyonrails-talk\
**Created:** [May 11, 2010, 3:05pm UTC](https://discuss.rubyonrails.org/t/can-access-the-through-attributes-from-the-many-with-has-many-through/51558 "2010-05-11T15:05:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dino\_d](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@dino\_d](https://discuss.rubyonrails.org/u/dino_d)\
**Post date:** [May 11, 2010, 3:05pm UTC](https://discuss.rubyonrails.org/t/can-access-the-through-attributes-from-the-many-with-has-many-through/51558/1 "2010-05-11T15:05:14Z")

</div>

hi -

if i have

A has\_many B A has\_many C through B

Is there any way to retrieve the B attributes once I have a C object?

For example:

class User \< ...

has\_many :friend\_links has\_many :friends, :through =\> :friend\_links, :class =\> User ...

friends = user.friends for f in friends &nbsp;&nbsp;link = f.friend\_link #i want to get the through object because i store some metrics here

is this possible? i realize i can just ignore the through and just grab the friend\_links directly, but i have various types of friends, some are borne of friend\_links, others have a different genesis, and i'd like to just treat them in one fell swoop, and if one of them happens to be born of a through, i'll do one thing, but otherwise, i'll do something else.

thanks for any help, dino

---

<div class="post-metadata">

**Author:** ![Colin\_Law1](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Colin\_Law1](https://discuss.rubyonrails.org/u/Colin_Law1)\
**Post date:** [May 11, 2010, 3:18pm UTC](https://discuss.rubyonrails.org/t/can-access-the-through-attributes-from-the-many-with-has-many-through/51558/2 "2010-05-11T15:18:17Z")

</div>

> hi -
> 
> if i have
> 
> A has\_many B A has\_many C through B
> 
> Is there any way to retrieve the B attributes once I have a C object?

Assuming that you also have B has\_many C C belongs\_to B

then if you have a C in @c you can say @c.b

Colin
