simply_stored
simply_stored copied to clipboard
validate_numericality_of 'property quantity, :type => Fixnum' not as expected
I have a form with a text field, for which I'd like to validate the contents as numerical.
Unfortunately, properties defined with a type are typecast on assignment (this is couch_potato behavoir, I believe). So if I assign a string to a property of type Fixnum, the value is typecast (meaninglessly) to 0.
class Product
include SimplyStored::Couch
include Validatable
property :quantity, :type => Fixnum
validates_numericality_of :quantity
end
p= Product.new(:quantity => "not a number")
p.valid? # => true
p.quantity # => 0
Has anyone else come across this? Any advice on how to handle this? It seems like it might be reasonable behavior from the perspective of couch_potato, which has something like 'statically typed' attributes. But it certainly doesn't make sense in the context of validations.
I've recently also run into this and the problem is as you said that CouchPotato casts on assignment. I'll see that I talk to Alex of CouchPotato. The only good place to fix this is in CouchPotato.