[Dbix-class] Re: DBIx::Class::Validation doesn't seem to work

fREW Schmidt frioux at gmail.com
Wed Jul 8 15:03:34 GMT 2009


On Tue, Jul 7, 2009 at 5:31 PM, fREW Schmidt <frioux at gmail.com> wrote:

> So this is really weird,
>
> I am trying to use DBIx::Class::Validation and it never seems to run at
> all!  (that is, the filters don't get run and defaults don't get set)
>
> Also, if I use any of the closures (not commented out code) I get a compi=
le
> time error.  Does anyone see anything wrong with the following code?
>
>
>> package ACD::Schema::Result::CustomerContact;
>> use base DBIx::Class;
>> use strict;
>> use warnings;
>> use Method::Signatures::Simple;
>> use CLASS;
>>
>> CLASS->load_components(qw/Validation InflateColumn::Capitalize Core/);
>>
>> CLASS->table('CustomerContacts');
>>
>> CLASS->add_columns(qw/
>>    id
>>    customer_id
>>    first_name
>>    last_name
>>    phone
>>    fax
>>    email
>>    is_repair
>>    is_accounts_payable
>>    /);
>>
>>
>> CLASS->add_columns(
>>    first_name =3D> {
>>       capitalization =3D> 'title_case'
>>    },
>>    last_name =3D> {
>>       capitalization =3D> 'title_case'
>>    },
>> );
>>
>> CLASS->set_primary_key('id');
>>
>> CLASS->belongs_to('customer' =3D> 'ACD::Schema::Result::Customer',
>> 'customer_id');
>> CLASS->has_many('workorders' =3D> 'ACD::Schema::Result::WorkOrder',
>> 'contact_id');
>>
>> use Data::FormValidator::Constraints qw(:closures);
>> CLASS->validation(
>>    module =3D> 'Data::FormValidator',
>>    profile =3D> {
>>       defaults =3D> {
>>      is_repair =3D> 0,
>>      is_accounts_payable =3D> 0,
>>       },
>>       constraint_methods =3D> {
>>      #email      =3D> email(),
>>      #first_name =3D> FV_min_length(1),
>>      #last_name  =3D> FV_min_length(1),
>>       },
>>       filters =3D> ['trim'],
>>       optional =3D> [qw{
>>      first_name
>>      last_name
>>      email
>>      phone
>>      fax
>>      is_repair
>>      is_accounts_payable
>>       }],
>>       missing_optional_valid =3D> 1,
>>    },
>>    filters =3D> 1,
>>    auto =3D> 1,
>> );
>>
>> 1;
>>
>
>
Ok, so after reading some of the tests I got it to work partially.  It
appears that the (documented) usage above isn't actually supported.  This
works though:

CLASS->validation_module('Data::FormValidator');
> CLASS->validation_profile({
>       defaults =3D> {
>      is_repair =3D> 0,
>      is_accounts_payable =3D> 0,
>       },
>       constraint_methods =3D> {
>      #email      =3D> email(),
>      #first_name =3D> FV_min_length(1),
>      #last_name  =3D> FV_min_length(1),
>       },
>       filters =3D> ['trim'],
>       optional =3D> [qw{
>      first_name
>      last_name
>      email
>      phone
>      fax
>      is_repair
>      is_accounts_payable
>       }],
>       missing_optional_valid =3D> 1,
>    });
>
> CLASS->validation_filter(1);
>
CLASS->validation_auto(1);
>

Also, there is a really weird bug that means I can't just do
$row->update($params);  I have to do $row->update($params); $row->update();

And for some reason it ignores my defaults...




-- =

fREW Schmidt
http://blog.afoolishmanifesto.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20090708/7e8=
a4793/attachment.htm


More information about the DBIx-Class mailing list