What is the correct association for this problem?
There are three models:
- Residents
- Parties
- Addresses
Each Resident
and Party
has an Address
Each Address
can belong to a Resident
or Party
or to both.
There can be multiple Parties
at the same Address
and multiple Residents
living at that location.
Is a habtm relationship the best solution for these models?
I looked into doing polymorphic associations but a conflict arises because an Address
might belong to both Resident
and to Party
mulitple times
I would like to be able to do things like...
address = Address.find_or_create_by_street("100 Some Street")
# Associate the Party with a specific Address:
party_object.address = address
# Find all Parties happening at a specific Address:
address.parties do ...
# Find all Residents located at a specific Address:
address.residents.each do ...
Running Rails 3 + MySQL 5.5