I've come across the need in my project to use DataMapper contextual validations to group different validations for different stages of data collection. I'm running into some major issues however. The way I understood from the wiki documentation, when I define a validation without a :when clause, it should apply globally, right? For data integrity sake, I should be able to specify validations for properties that should be checked, no matter what the validations context. And then add specific contextual validations on top, for the special cases.
However, this doesn't seem to be the case. When I decide to activate validations for a detailed case, it seems to just drop any validations I defined at the global level. Here's an easily reproducable example. Given the model "Article" as defined: class Article include DataMapper::Resource property :id, Integer, :serial => true property :name, String property :body, Text validates_present :name validates_present :body, :when => [:posting] end a1 = Article.new a1.valid? #=> false a1.errors.on(:name) #=> ["Name must not be blank"] (makes sense so far) a2 = Article.new a2.valid?(:posting) #=> false a2.errors.on(:name) #=> nil (where did my :name validation go?) a2.errors.on(:body) #=> ["Body must not be blank"] (it only picked up the body validation) Am I doing something wrong? Is there an alternate way to specifiy a validation that works on all contexts without having to maintain a huge list of all the different possibilities? Thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
