# Create method calling wrong column name in a table

**URL:** <https://www.ruby-forum.com/t/create-method-calling-wrong-column-name-in-a-table/115021>\
**Category:** Rails\
**Created:** [September 19, 2007, 8:12pm UTC](https://www.ruby-forum.com/t/create-method-calling-wrong-column-name-in-a-table/115021 "2007-09-19T20:12:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![whitewolfaustria](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/bbce88/32.png) [@whitewolfaustria](https://www.ruby-forum.com/u/whitewolfaustria)\
**Post date:** [September 19, 2007, 8:12pm UTC](https://www.ruby-forum.com/t/create-method-calling-wrong-column-name-in-a-table/115021/1 "2007-09-19T20:12:48Z")

</div>

I have a multitable database with an observer logging changes into a  
datachange table.

The create method inserts the data into the data change table, updates  
my model, and then trys to load from the datachange table. When it  
does this it WHERE clause that is generated for me is looking for a  
column model\_id which I dont have. I don’t want to even have a field  
because this table will be loggin changes for all models and having  
the ids stored is undesirable.

The generated sql statment is SELECT \* FROM datachanges WHERE  
datachanges.model\_id = 56  
where 56 is the id of the model

Any help to fix this error would be appreciated

---

<div class="post-metadata">

**Author:** ![whitewolfaustria](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/bbce88/32.png) [@whitewolfaustria](https://www.ruby-forum.com/u/whitewolfaustria)\
**Post date:** [September 19, 2007, 8:19pm UTC](https://www.ruby-forum.com/t/create-method-calling-wrong-column-name-in-a-table/115021/2 "2007-09-19T20:19:36Z")

</div>

Since it generates that SQL based on what you specify in your model and  
migration code, you should post the relevant snippets of that code.

---

<div class="post-metadata">

**Author:** ![whitewolfaustria](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/bbce88/32.png) [@whitewolfaustria](https://www.ruby-forum.com/u/whitewolfaustria)\
**Post date:** [September 19, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/create-method-calling-wrong-column-name-in-a-table/115021/3 "2007-09-19T20:27:57Z")

</div>

On Sep 19, 2007, at 12:12 PM, White W. wrote:

> I don’t want to even have a field  
> because this table will be loggin changes for all models and having  
> the ids stored is undesirable.
> 
> The generated sql statment is SELECT \* FROM datachanges WHERE  
> datachanges.model\_id = 56  
> where 56 is the id of the model

Do you have a belongs\_to :model statement?  
That would cause it to expect to find a model\_id column.

---

<div class="post-metadata">

**Author:** ![whitewolfaustria](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/bbce88/32.png) [@whitewolfaustria](https://www.ruby-forum.com/u/whitewolfaustria)\
**Post date:** [September 20, 2007, 3:41pm UTC](https://www.ruby-forum.com/t/create-method-calling-wrong-column-name-in-a-table/115021/4 "2007-09-20T15:41:26Z")

</div>

Thank you ,  
Your help enabled me to solve my problem
