# Setting up has\_many

**URL:** <https://www.ruby-forum.com/t/setting-up-has-many/186033>\
**Category:** Rails\
**Created:** [March 30, 2010, 6:50pm UTC](https://www.ruby-forum.com/t/setting-up-has-many/186033 "2010-03-30T18:50:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ESESES](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f0a364/32.png) [@ESESES](https://www.ruby-forum.com/u/ESESES)\
**Post date:** [March 30, 2010, 6:50pm UTC](https://www.ruby-forum.com/t/setting-up-has-many/186033/1 "2010-03-30T18:50:28Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![ESESES](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f0a364/32.png) [@ESESES](https://www.ruby-forum.com/u/ESESES)\
**Post date:** [March 30, 2010, 6:58pm UTC](https://www.ruby-forum.com/t/setting-up-has-many/186033/2 "2010-03-30T18:58:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ESESES](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f0a364/32.png) [@ESESES](https://www.ruby-forum.com/u/ESESES)\
**Post date:** [March 30, 2010, 7:00pm UTC](https://www.ruby-forum.com/t/setting-up-has-many/186033/3 "2010-03-30T19:00:25Z")

</div>

got it, thanks!
