On Tue, Jul 7, 2009 at 5:31 PM, fREW Schmidt <[email protected]> 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 compile
> 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 => {
>>       capitalization => 'title_case'
>>    },
>>    last_name => {
>>       capitalization => 'title_case'
>>    },
>> );
>>
>> CLASS->set_primary_key('id');
>>
>> CLASS->belongs_to('customer' => 'ACD::Schema::Result::Customer',
>> 'customer_id');
>> CLASS->has_many('workorders' => 'ACD::Schema::Result::WorkOrder',
>> 'contact_id');
>>
>> use Data::FormValidator::Constraints qw(:closures);
>> CLASS->validation(
>>    module => 'Data::FormValidator',
>>    profile => {
>>       defaults => {
>>      is_repair => 0,
>>      is_accounts_payable => 0,
>>       },
>>       constraint_methods => {
>>      #email      => email(),
>>      #first_name => FV_min_length(1),
>>      #last_name  => FV_min_length(1),
>>       },
>>       filters => ['trim'],
>>       optional => [qw{
>>      first_name
>>      last_name
>>      email
>>      phone
>>      fax
>>      is_repair
>>      is_accounts_payable
>>       }],
>>       missing_optional_valid => 1,
>>    },
>>    filters => 1,
>>    auto => 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 => {
>      is_repair => 0,
>      is_accounts_payable => 0,
>       },
>       constraint_methods => {
>      #email      => email(),
>      #first_name => FV_min_length(1),
>      #last_name  => FV_min_length(1),
>       },
>       filters => ['trim'],
>       optional => [qw{
>      first_name
>      last_name
>      email
>      phone
>      fax
>      is_repair
>      is_accounts_payable
>       }],
>       missing_optional_valid => 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
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to