Im trying to set up a has one
relationship in RoR. An agreement has one contact. In the agreement table there is a column called contact_id
.
When i try to call an agreenment's contact like so: <%= agreement.contact.name %>
(contact table has a column name
) I get the error Unknown column 'contacts.agreement_id'
Where it should be looking for agreement.contact_id
Any suggestions?
Your
contacts
table needs the foreign key migration added, i.e. you need to create a columnagreement_id
as integer. Make sure you dorake db:migrate
and this should work.Remember, the FK is on the 'belongs_to' table side of the relationship. So, an agreement
has_one
contact and contactbelongs_to
agreement.