class Photo < ActiveRecord::Base
has_many :boosts, class_name: BoostedPhoto
...
end
class BoostedPhoto < ActiveRecord::Base
belongs_to :photo
end
This is how I have it set up so far, but when i try to do this in the console:
photo = Photo.first
photo.boosts.create(title: 'testing')
I get the following results
(0.3ms) begin transaction
(0.1ms) rollback transaction
ActiveRecord::UnknownAttributeError: unknown attribute: photo_id
Been looking up how to do relationships for a few hours, and I think I might be overlooking something really simple...sorry for the newb question, but I'm starting to pull my hair out from frustration!
There should be a foreign key column in the boosted_photos
table. General rule is the we put belongs_to
association in the table model which have the foreign key, here it is BoostedPhoto
After that following should work,
photo = Photo.first
photo.boosts.create(title: 'testing')