Hello all, I want to build something so that a person can have many email addresses and an email address has only one person, but because I also have another model called Company that also can have many email addresses, and I don't want to have columns company_id and person_id in the Emails table, so I thought I can do ...
person.rb
has_many :person_emails has_many :emails, :through => :person_emails
person_emails.rb
belongs_to :person belongs_to :email
email.rb
has_one :person_email has_one :person, :through => :person_email
What's happening now is that...
p = Person.first #=> "Nik" p.emails #=> shows all emails Nik has p.person_emails #=> shows all person_email joint table records for Nik
e = Email.first #=> one of Nik's email addresses e.person_email #=> shows this email's one and only one person_email joint table record e.person # fails saying that unknown column "people.email_id" in where-clause
I'd like... e.person #=> "Nik"
Does anyone have an idea what the problem might be?
Thank You