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

**URL:** <https://www.ruby-forum.com/t/can-access-the-through-attributes-from-the-many-with-has-many-through/188414>\
**Category:** Rails\
**Created:** [May 11, 2010, 5:06pm UTC](https://www.ruby-forum.com/t/can-access-the-through-attributes-from-the-many-with-has-many-through/188414 "2010-05-11T17:06:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dino\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dino\_d](https://www.ruby-forum.com/u/dino_d)\
**Post date:** [May 11, 2010, 5:06pm UTC](https://www.ruby-forum.com/t/can-access-the-through-attributes-from-the-many-with-has-many-through/188414/1 "2010-05-11T17:06:48Z")

</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  
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:** ![dino\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dino\_d](https://www.ruby-forum.com/u/dino_d)\
**Post date:** [May 11, 2010, 5:20pm UTC](https://www.ruby-forum.com/t/can-access-the-through-attributes-from-the-many-with-has-many-through/188414/2 "2010-05-11T17:20:16Z")

</div>

On 11 May 2010 16:05, dino d. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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
