Confusion about ActiveRecord associations and foreign keys (Ruby/Rails)
In the below example, do I have to create "employee_id" in the office
model, or is it created automatically by db:migrate?
class Employee < ActiveRecord::Base
has_one :office
end
class Office < ActiveRecord::Base
belongs_to :employee # foreign key - employee_id
end
Sorry, feels like I'm missing something fundamental. I'm trying to get a
basic one to many relationship working, where I can use a dropdown select
of objects from the one side. Are there any good basic tuts explaining how
this works?
I had to create "_id"s in all the models where I wanted this to work, but
it doesn't seem right from examples I've looked at.
No comments:
Post a Comment