belongs_to :type, :class_name => "ItemType"

'type' is used by ActiveRecord to indicate Single Table Inheritance.

That's probably tripping you up (esp. since changing the name
eliminates the issue)

At the ruby level, type is an alias of class, too (sorta), so it's gonna have some major issues with that word.

Rob Biedenharn wrote:

'type' is used by ActiveRecord to indicate Single Table Inheritance.

That's probably tripping you up (esp. since changing the name eliminates the issue)

As far as I know this is only the issue when you name a column "type" -which is not what I've done here.

Thanks anyway :slight_smile:

Rasmus Nielsen wrote:

Yes I know - but why doesn't

belongs_to :blah, :class_name => "ItemType"

... not work then?

Does it work when you explicitly define the foreign_key?

Wouter de Bie wrote:

Rasmus Nielsen wrote:

Yes I know - but why doesn't

belongs_to :blah, :class_name => "ItemType"

... not work then?

Does it work when you explicitly define the foreign_key?

Xinit and Michael: thank you.

It worked after specifying the foreign key explicitly. This saved me a big headache! Thank you very much! :slight_smile:

Should I file this surprising behavior as a bug?

It's bad practice to have an association or method called type because
ruby already defines One IMHO

If you set self.inheritance_column = nil on the model this may work.