How do I model a has_many :through and with aggregation in Rails?
- by Angela
How do I model having multiple Addresses for a Company and assign a single Address to a Contact?
Contacts belong_to a Company.
A Company has_many Contacts.
A Company also has_many Addresses.
And each Contact belongs_to an Address.
How do I model this?
I have
Model/Contacts.rb
belong_to :Company
belong_to :Address (?)
Model/Company.rb
has_many :Contacts
has_many :Addresses
Address is an aggregation of :street1, :street2, :city, :state, :zip so not clear exactly what to do there.
So what would I do in my _form so that when I have a contact/new I am able to either default to a main address or select one of the others? If none of them match, adding for a Contact makes that address available to any subsequent contact?