
Enum properties become nil after loading
Reported by Sebastian | March 1st, 2011 @ 04:09 PM
Hello,
I couldn't find any answer to this problem, so I am filing a bug report.
After defining an Enum property on a class, inserting a record, and loading that record, the value of the Enum propery is always nil.
Strangely, the Enum property listed in
<class>.properties
does not have a class name
(see example below). Maybe the Enum class does not get included
properly?
sebastian@sebastian:~ $ irb
ruby-1.9.2-p0 > require 'dm-types'
=> true
ruby-1.9.2-p0 > class A
ruby-1.9.2-p0 ?> include DataMapper::Resource
ruby-1.9.2-p0 ?> property :enumeration, Enum[:x, :y, :z]
ruby-1.9.2-p0 ?> storage_names[:default] = 'A'
ruby-1.9.2-p0 ?> end
=> #< @model=A @name=:enumeration>
ruby-1.9.2-p0 > DataMapper.setup(:default, "mysql://root@localhost/test")
=> #<DataMapper::Adapters::MysqlAdapter:0x94738f4 @name=:default, [...]
ruby-1.9.2-p0 > A.count()
=> 0
ruby-1.9.2-p0 > A.create(:enumeration => :x)
=> #<A @enumeration=:x>
ruby-1.9.2-p0 > A.count()
=> 1
ruby-1.9.2-p0 > A.find().first
=> #<A @enumeration=nil>
ruby-1.9.2-p0 > A.properties
=> [#< @model=A @name=:enumeration>]
ruby-1.9.2-p0 > A.properties.first.class
=> #<Class:0x95a66a4>
- Linux sebastian 2.6.32-5-686 #1 SMP Wed Jan 12 04:01:41 UTC 2011 i686 GNU/Linux
- Gems
- dm-aggregates (1.0.2)
- dm-core (1.0.2)
- dm-do-adapter (1.0.2)
- dm-mysql-adapter (1.0.2)
- dm-sweatshop (1.0.2)
- dm-types (1.0.2)
- RVM Ruby
- rvm 1.0.20 by Wayne E. Seguin
- => ruby-1.9.2-p0 [ i386 ]
- mysql Ver 14.14 Distrib 5.1.49, for debian-linux-gnu (i486) using readline 6.1
Comments and changes to this ticket
-
Sebastian March 2nd, 2011 @ 04:17 AM
- Title changed from Enum properties always take nil after loading to Enum properties become nil after loading
-
Piotr Solnica (solnic) March 2nd, 2011 @ 05:32 AM
- State changed from new to not-applicable
I couldn't reproduce that behavior. Marking as not-applicable. One comment tho - your example model is not valid as it doesn't have any key. If you call DataMapper.finalize, which you need to do, you will get an exception that your model is not complete. Regarding missing name of the property class - it's a minor bug in #inspect which we override. I will fix that. DataMapper 1.1.0.rc2 was released yesterday, please give it a try.
-
Sebastian March 2nd, 2011 @ 05:48 AM
Thank you. Adding an ID field didn't change anything, I still get the same behavior, see attached test. Any other ideas?
-
-
Sebastian March 3rd, 2011 @ 01:28 PM
Hello,
Still not working for me, same as with previous version: Enum properties are always nil.
Could you reproduce that behavior in the previous version? Did the new version resolve the issue for you?
What was the problem then, what solved it?
Which part of Datamapper does actually fetch data and populate model instances? Could you point me in the right direction so I can investigate the issue further?
%> bundle exec ruby dm_enum_test.rb #<A @id=1 @e=nil> [#<DataMapper::Property::Serial @model=A @name=:id>, #< @model=A @name=:e>] %> bundle show * ParseTree (3.0.7) * RubyInline (3.9.0) * ZenTest (4.5.0) * activesupport (3.0.5) * addressable (2.2.4) * bcrypt-ruby (2.1.4) * bundler (1.0.7) * data_objects (0.10.3) * dm-aggregates (1.1.0.rc2 e2df464) * dm-core (1.1.0.rc2 c0eea1c) * dm-do-adapter (1.1.0.rc2) * dm-mysql-adapter (1.1.0.rc2 6f8303a) * dm-sweatshop (1.1.0.rc2 5a179fb) * dm-types (1.1.0.rc2 ced0071) * do_mysql (0.10.3) * fastercsv (1.5.4) * i18n (0.5.0) * json (1.4.6) * randexp (0.1.5) * sexp_processor (3.0.5) * stringex (1.2.0) * uuidtools (2.1.2) * wxruby-ruby19 (2.0.0)
-
Piotr Solnica (solnic) March 3rd, 2011 @ 01:40 PM
I still can't reproduce it. Give me more information about your env. Which ruby, which mysql etc.
Here's the exact script I used: https://gist.github.com/853367
-
Sebastian March 3rd, 2011 @ 05:22 PM
Working now!
The MySQL table I was using defined the enumeration property as
enum('a','b','c')
. However,auto_migrate!
is creating anINTEGER
field for the same property.Thanks and sorry for the confusion.
-sebastian
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »