# Active record associations

**URL:** <https://www.ruby-forum.com/t/active-record-associations/64165>\
**Category:** Rails\
**Created:** [June 22, 2006, 6:25pm UTC](https://www.ruby-forum.com/t/active-record-associations/64165 "2006-06-22T18:25:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![crenner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/278dde/32.png) [@crenner](https://www.ruby-forum.com/u/crenner)\
**Post date:** [June 22, 2006, 6:25pm UTC](https://www.ruby-forum.com/t/active-record-associations/64165/1 "2006-06-22T18:25:35Z")

</div>

I have a table containing a person’s info:

Person  
{  
first\_name : string  
last\_name : string  
height : int  
weight : int  
age : int  
}

This person can belong to many leagues and 0 or 1 teams within that  
league. I can create join tables and use the following associations:

League has\_and\_belongs\_to\_many people  
Team has\_and\_belongs\_to\_many people  
League has one team  
Team belongs to league

This will let me query for a person through his league or through his  
team, but I wouldn’t be able to do something like:

person = League.people.find(person\_id)  
team = person.team \<-- the team for that league (if any)

Is there a way that I could set things up so that if I query by league,  
the person I get back only knows about the team it plays for in that  
league opposed to all leagues?

Thank you for any help you can provide!
