Hey,
info inserted below:
On 18-Jun-06, at 2:41 PM, Gokhan A. wrote:
t.column "updated_at", :time
config.define ‘Gender’,
:extends => ‘Enum’
config.define ‘Eye’,
:extends => ‘Enum’
end
Okay, you are using STI when you say :extends => ‘Enum’, which means
that (be default) you need a ‘type’ column in your table. However,
it seems you’ve got an ‘enumeration_type’ column in your migration
which is doing that job right?
In that case you need to define the ‘Enum’ virtual enumeration like
this:
ActiveRecord::VirtualEnumerations.define do |config|
config.define ‘Enum’, :order => ‘position ASC’ do
set_inheritance_column ‘enumeration_type’
end
the rest of your virtual enums …
end
more below:
and in my User model
has_enumerated :gender, :class_name => ‘Enum’
DON’T say :class_name => ‘Enum’. If you do that it will allow
assign any subclass of Enum to the :gender attribute and I doubt
that’s what you want (i.e. foo.gender = Status[:open]).
You should be able to just say:
has_enumerated :gender
Or, if you want to be ultra-verbose about it:
has_enumerated :gender, :class_name => ‘Gender’
more below:
end
Enum.create(:enumeration_type => "Gender", :name=>"m", :position=>
“1”)
Enum.create(:enumeration_type => “Gender”, :name=>“f”, :position=>
“2”)
Hrm… did this migration actually run? Because of the caching I try
to protect myself from my own stupidity by demanding extra steps
before allowing any alterations to aae model data.
Gender.enumeration_model_updates_permitted = true
Gender.create(:name => ‘m’, :position = 1)
Gender.create(:name => ‘f’, :position = 2)
The enumeration_model_updates_permitted thing is long and unruly to
type and is there as a way of saying “yes dammit, I know what I’m
doing, just update the damn data okay?”
However, you’ve got a more important issue and none of this will
work till you fix it. Se below:
“mobile”=>nil, “region_id”=>nil, “birthday”=>nil, “phone”=>nil,
from
That stacktrace is all wrong - as in the virtual_enumerations code
hasn’t loaded (and I think there’s a good reason for that). Here’s
what my stacktrace looks like when it can’t find a class:
NameError: uninitialized constant Gender
from ./script/…/config/…/config/…/vendor/rails/
activerecord/lib/…/…/activesupport/lib/active_support/
dependencies.rb:123:in enumerations_original_const_missing' from ./script/../config/../config/../vendor/plugins/ enumerations_mixin/lib/active_record/virtual_enumerations.rb:63:in
const_missing’
from ./script/…/config/…/config/…/vendor/rails/
activerecord/lib/…/…/activesupport/lib/active_support/
dependencies.rb:131:in `const_missing’
from (irb):2
Notice that the first ‘from’ line in my stacktrace complains about
the ‘enumerations_original_const_missing’ method while yours just
says ‘const_missing’.
So, assuming that the plugin has loaded (and you don’t get complaints
about ‘has_enumerated’ being undefined when you load your User model)
then it’s going to be the fact that the plugin didn’t see your
virtual_enumerations.rb file (the plugin won’t patch the rails class
loading code if that file isn’t found).
Make sure your virtual_enumerations.rb file is in the config
directory (the same one as your database.yml file).
Let me know how you get on with this - I’ll be out of contact from
Monday morning until Wednesday afternoon though so if I don’t
respond … that’s why.
Regards,
Trevor