# Strange problems with belongs\_to()

**URL:** <https://www.ruby-forum.com/t/strange-problems-with-belongs-to/163854>\
**Category:** Rails\
**Created:** [March 25, 2009, 3:08pm UTC](https://www.ruby-forum.com/t/strange-problems-with-belongs-to/163854 "2009-03-25T15:08:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [March 25, 2009, 3:08pm UTC](https://www.ruby-forum.com/t/strange-problems-with-belongs-to/163854/1 "2009-03-25T15:08:05Z")

</div>

Hey.

I am a bit confused, seems to be simple thing, but anyhow it does not  
work for me:

class Foo  
has\_many(:bars)  
end

class Bar  
belongs\_to(:myfoo, :class\_name =\> ‘Foo’)  
end

b = Bar.new().  
b.myfoo = Foo.find\_by\_name(‘COOKIE\_MONSTER’)  
b.save()

The bar table got a FK field for Foo: “foo\_id”. As long as I do not  
choose an extra relation name, this works. But in this case, when I  
name the relation “myfoo” and give informationen about the class name,  
ActiveRecord fails an says \<Column ‘foo’ does not exist.\> Why is there  
no “\_id” appended? I also tried to deliver the :foreign\_key parameter,  
but I did not succeed.

As I said: If I name the relation “foo”, all the things work.

Do you have an idea?

Thanks for helping! Cheers, ms
