Active record associations

I have a table containing a person’s info:

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 = <-- 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!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs