Setting up has_many

Do I have to manually set a column in a dependent table for the id of
the object to which it belongs?

I have a collection of objects called photos that are owned by a
analysis object. When I try to show an attribute of each of the photo
objects I get this error:

Mysql::Error: Unknown column ‘photos.analysis_id’ in ‘where clause’:
SELECT * FROM photos WHERE (photos.analysis_id = 7)

Extracted source (around line #1):

1: <% for photo in @analysis.photos %>
2:


3: <%= photo.description %>
4:

The normal rails convention is to use the table_id as the fk. You can
over ride this in the model if need be.

So if analysis :has_many => :photos

the photo table would have a column analysis_id.

got it, thanks!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs