There might be a better way, but basically:

prop = ObjectClass.properties[:qty]

puts my_object.dirty_attributes[prop]
puts my_object.original_attributes[prop]


On 17/06/2011, at 02:03, Javier wrote:

> Hi,
> 
> I wanted to check values before being saved, for example like this:
> 
>    myobject.qty = 5
>    myobject.save
> 
>    class ObjectClass
>        include DataMapper::Resource
>        before :save, :fix_qty
> 
>        def fix_qty
>            if self.dirty.qty > self.qty
>                # do something
>            end
>        end
>    end
> 
> "self.dirty.qty" should have the new assigned value, and "self.qty"
> the value from database
> 
> How should I do that?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "DataMapper" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/datamapper?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to