[Dbix-class] DBIx::Class, another data validation approach

Ulrich Kautz uk.lists at fortrabbit.de
Sat Jul 25 18:31:40 GMT 2009


--%<--
>> [...] a short introduction of the multiple approaches and methods
>> you can follow to achieve validation.
>> 
>> Most of them could be combined and are not "either-or".
>> 
>> * Validation profiles These are ment to be used in most complex
>> validation scenarios. You can validate the data with multiple
>> profiles (one after another, chained) with one call.
>> 
>> * Inline column validation Directly in the column definition via
>> add_column they are most simple and fast. Also the definition of
>> the columns is not apart from the defi‐ nition of the validation.
>> 
>> They are limited because they have to fit always (each save) and
>> cannot be used, as validation profiles, only in certain
>> circumstances.
>> 
> 
> I'm not completely sure what you mean by this.  Are you trying to say
> that column validation is used for both inserts and updates no matter
> what profile you are using?

Yes, column validation always applies! In opposite to profiles you can't trigger them on or off, especially there is no trigger to switch only certain column validations on or off (as you can do with profile validation). Excuse my poor english, little bit out of practice, i'll try to write it more clearly..


--%<--
>> 
>> Please read the POD in DBIx::Class::DataValidator for more info..
>> 
>> Despite what i wrote above about 0.9, i think i could provide DBMS
>> specific validation for MySQL and PostgreSQL before i release this
>> to CPAN (but in sepparate packages, due to dependencies), but first
>> of all i would like to hear what you all think  about the
>> usefullness at all.
>> 
>> Nice weekend to everybody! Ulrich
> 
> 
> Thanks for spending your time on this!  I looked through your tests
> and briefly read some code and I think this will do quite nicely.
> Just a couple questions: does it only validate when you call
> create_validated or can you have create validate by default?  Same
> for update and the $rs version of update.

No problem, actually i'm using this - so i do benefit myself ;)

Yes, validation is only performed on (update|update_all|create)_validated. Maybe this is a based on the development history. I merged a (Catalyst) app, where i use this, slowy from controller validation to model validation. However, i think its more readable if you still use both (validation and no validation) - especially for the profile validation (at which you provide the profile names as 2++ arguments), but i can implement an "enable_native_validation"-switch, or so. A possibility to use the "non-validation"-methods should always exist.


Ulrich




More information about the DBIx-Class mailing list