
STI + Lazy Text + Validation bug
Reported by David Kelso | June 18th, 2009 @ 04:22 AM | in 0.10.0
It took me a while to track down, but I've found a crazy corner case bug involving STI, Lazy Text loading and validation.
Here is a pastie of the code:
http://pastie.org/516158
I'm pretty new to DM, so please let me know if I've done anything wrong, of if you need me to post my test case in a different manner.
Thanks!
david
Edit
Gem versions are as follows
* dm-core (0.9.11) * dm-validations (0.9.11)
Comments and changes to this ticket
-
Martin Gamsjaeger (snusnu) July 12th, 2009 @ 01:50 PM
- State changed from new to resolved
- Milestone set to 0.10.0
I just ran your pastie against the current next branch and get the expected behavior. Marking this as resolved.
require 'rubygems' require 'dm-core' require 'dm-validations' class Element include DataMapper::Resource property :id, Serial property :type, Discriminator property :val, Integer end class LazyTextbox < Element property :content, Text, :lazy => false validates_present :content end class ActiveTextbox < Element property :content, Text validates_present :content end class LazyUnvalidatedTextbox < Element property :content, Text, :lazy => false end DataMapper.setup(:default, "sqlite3:///#{Dir.pwd}/content.db") DataMapper.auto_upgrade! lazy = LazyTextbox.create({:val => 10, :content => 'hello'}) active = ActiveTextbox.create({:val => 10, :content => 'hello'}) unvalid = LazyUnvalidatedTextbox.create({:val => 10, :content => 'hello'}) # Doesn't work! e = Element.get lazy.id e.val = 20 puts e.save puts e.val # Works when accessing the child class e = LazyTextbox.get lazy.id e.val = 20 puts e.save puts e.val # Works when not lazy loaded e = Element.get active.id e.val = 20 puts e.save puts e.val # Works when not validated e = Element.get unvalid.id e.val = 20 puts e.save puts e.val #mungo:snippets snusnu$ ruby 910.rb #true #20 #true #20 #true #20 #true #20
-
David Kelso July 18th, 2009 @ 11:00 PM
Would love to test this out - is there an easy way to install 0.10 ? Can you point me towards any instructions?
-
Dan Kubb (dkubb) July 19th, 2009 @ 12:48 AM
@David: Unfortunately it's not super easy, but it's not too hard, it'll probably take a few minutes to pull everything down and install it.
The easiest way is to git clone extlib, do, dm-core and dm-more from the http://github.com/datamapper/ account. Then checkout the next branch, and run sudo rake install to install the edge gems. Make sure you install them in this order since each package is dependent on the one before it.
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 »