I'm looking to give an object (buyer) a status. What's the best way to
accomplish this? At the moment, I'm struggling to comprehend my way
through the following:
1) Create a status model, then let the user add statuses as they see
fit. These statuses can then be applied to a buyer. The buyer table
will have a status_id column. This works fine, but I have a problem when
I try to refer to the the status through a buyer.
buyer.status gives me the following error:
Unknown column 'statuses.buyer_id' in 'where clause': SELECT * FROM
`statuses` WHERE (`statuses`.buyer_id = 12) LIMIT 1
I see what it's trying to do - go into the status column and find all
statuses that have the buyer_id assigned. The problem is that I don't
want a status to apply to only ONE buyer, I want them to be able to
apply to multiple.
I'm sure I'm missing something in my routes, or just not understanding
the relationship and how I need to instruct rails of this.
Can someone help me out? Thanks in advance for any time spent helping.
The big difference between has_one and belongs_to is that ActiveRecord
expects the model that uses the belongs_to to have a foreign key
identifying the associated record in the other table. So, therefore
you know you need to use a belongs_to in Buyer because that the buyers
table is where you have defined the status_id field.