Forum: Ruby on Rails Strange problems with belongs_to()

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
ms (Guest)
on 2009-03-25 15:57
(Received via mailing list)

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

class Foo

class Bar
  belongs_to(:myfoo, :class_name => 'Foo')

b = = Foo.find_by_name('COOKIE_MONSTER')

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
This topic is locked and can not be replied to.