# Accessing :through table attributes

**URL:** <https://www.ruby-forum.com/t/accessing-through-table-attributes/73136>\
**Category:** Rails\
**Created:** [October 21, 2006, 10:17pm UTC](https://www.ruby-forum.com/t/accessing-through-table-attributes/73136 "2006-10-21T22:17:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chadster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/46a35a/32.png) [@chadster](https://www.ruby-forum.com/u/chadster)\
**Post date:** [October 21, 2006, 10:17pm UTC](https://www.ruby-forum.com/t/accessing-through-table-attributes/73136/1 "2006-10-21T22:17:07Z")

</div>

If I have the following (abridged) setup:

class User \< ActiveRecord::Base

has\_many :groups, :through =\> :memberships

end

class Group \< ActiveRecord::Base

has\_many :users, :through =\> :memberships

end

and my memberships table has:

user\_id

group\_id

joined\_date

Let’s say I’ve got: @group.users.each do |user| . end

How do I access their joined\_date attribute? It’s gotta be easy but I  
can’t  
seem to figure it out. Do I need to write extra model code to pull out  
a  
single membership record?

Thanks,

Chad

---

<div class="post-metadata">

**Author:** ![chadster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/46a35a/32.png) [@chadster](https://www.ruby-forum.com/u/chadster)\
**Post date:** [October 21, 2006, 10:17pm UTC](https://www.ruby-forum.com/t/accessing-through-table-attributes/73136/2 "2006-10-21T22:17:07Z")

</div>

sorry for the spaces sent html on accident

---

<div class="post-metadata">

**Author:** ![chadster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/46a35a/32.png) [@chadster](https://www.ruby-forum.com/u/chadster)\
**Post date:** [October 21, 2006, 10:29pm UTC](https://www.ruby-forum.com/t/accessing-through-table-attributes/73136/3 "2006-10-21T22:29:11Z")

</div>

Hi –

On Sat, 21 Oct 2006, Chad A. wrote:

> and my memberships table has:
> 
> user\_id  
> group\_id  
> joined\_date
> 
> Let’s say I’ve got: @group.users.each do |user| . end
> 
> How do I access their joined\_date attribute? It’s gotta be easy but  
> I can’t seem to figure it out. Do I need to write extra model code  
> to pull out a single membership record?

The membership model exists to serve as the meeting place for all the  
info – so go directly for the memberships:

@group.memberships.each do |m|  
# do stuff with m.user and m.joined\_date  
end

David

–  
David A. Black | removed\_email\_address@domain.invalid  
Author of “Ruby for Rails” [1] | Ruby/Rails training & consultancy [3]  
DABlog (DAB’s Weblog) [2] | Co-director, Ruby Central, Inc. [4]  
[1] [Ruby for Rails](http://www.manning.com/black) | [3] [http://www.rubypowerandlight.com](http://www.rubypowerandlight.com)  
[2] [http://dablog.rubypal.com](http://dablog.rubypal.com) | [4] [http://www.rubycentral.org](http://www.rubycentral.org)

---

<div class="post-metadata">

**Author:** ![chadster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/46a35a/32.png) [@chadster](https://www.ruby-forum.com/u/chadster)\
**Post date:** [October 23, 2006, 8:52am UTC](https://www.ruby-forum.com/t/accessing-through-table-attributes/73136/4 "2006-10-23T08:52:58Z")

</div>

Ah… that’s perfect. I was trying to pull a list of members and get  
the membership info from that as opposed to pulling memberships and  
getting member info.

Thanks!
