Posted by Trevor Squires (Guest)
on 02.06.2006 01:30
On 1-Jun-06, at 2:26 PM, Josh Susser wrote:
>
> def inheritance_column
> "something_other_than_type"
> end
>
Sorry but that's not the way to go. The inheritance_column method is
a *class* method.
Regardless, I believe the correct call is set_inheritance_column. I.e.:
class MyModel < ActiveRecord::Base
set_inheritance_column :ruby_type
end
However, if you want to access the value for the 'type' field in your
table you can't do:
model.type
you have to use:
model[:type]
All in all, if you can avoid it then don't have a column called
"type". I don't even use it for STI - a while back I picked up a
habit of always setting the inheritance column to be 'ruby_type'.
That way I can do model.type() to get back the class object and
model.ruby_type (and model.ruby_type=) to access the string
representation of the class name.
Bookmarks