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

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

On Jan 29, 2009, at 12:13 PM, Rasmus Nielsen wrote:

>
> Hi there,
>
> I have a Item-model that belongs to the ItemType-model. This works  
> fine:
>
> class Item < ActiveRecord::Base
>  belongs_to :item_type
> end
>
> However, if I rewrite this to:
>
> class Item < ActiveRecord::Base
>  belongs_to :type, :class_name => "ItemType"
> end
>
> ... i get the following in the console:
>>> Item.first.type
> => nil
>
> When looking at my log I can see that no query are sent to the
> db-server. This does not work:
> class Item < ActiveRecord::Base
>  belongs_to :blah, :class_name => "ItemType"
> end
>
> However, this does:
> class Item < ActiveRecord::Base
>  belongs_to :item_type, :class_name => "ItemType" # I know this does
> not make sense
> end
>
> Can anybody explain what's going on there? Ultimately I would like  
> to be
> able to write Item.find(x).type.
>
> Thanks in advance! :-)
>
> - Rasmus
> -- 
> Posted via http://www.ruby-forum.com/.
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to