Hi Steven DataMapper has a strict validation of types. If you create a decimal property then the number type validation is inferred from the property declaration. This means if you pass a string as the property value you will have a validation failure since an empty string is not a nil and is not a number. You must manually typecast empty strings to nil to get that working.
It applies to every property type, not only Decimal, so be aware of that. It's a huge difference between DM and AR behavior which bites many people coming from AR world. It might be considered as an inconvenient behavior but it really boils down to the fact that AR has been built with web apps in mind whereas DataMapper is a general purpose ORM library. Assuming that every blank string should be converted into nil can be dangerous in various cases hence the strict approach to validation of types in DM. In my rails projects I have a before filter in app controller that clears empty values in params hash, you could use that approach too. It's possible we will add something like that to dm-rails project, maybe as a rack middleware. Cheers # solnic On May 1, 5:07 pm, Steven Garcia <[email protected]> wrote: > Given a model with the following field: > > property :price, Decimal, :precision => 10, :scale => 2 > > When I submit the form with a blank :price field, I get a validation error > "must be a number" > > Thing is I am not validating the presence of this field, shouldnt it only > perform that validation if the field is required?? -- 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.
