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

Alexander Hartmaier alexander.hartmaier at t-systems.at
Wed Jul 8 16:43:34 GMT 2009


I'm using it without problems.
That are the relevant lines of my result base class:

# validate by default
__PACKAGE__->validation_auto( 1 );
# don't filter by default
__PACKAGE__->validation_filter( 0 );
# use FVS for validation
__PACKAGE__->validation_module('FormValidator::Simple');

# generate the profile from the tables metadata
sub validation_profile {
    return shift->result_source_instance->get_fvs_profile;
}

get_fvs_profile is a sub defined the the resultsource base class which
returns a FVS profile generated from dbic metadata.

Am Mittwoch, den 08.07.2009, 17:03 +0200 schrieb fREW Schmidt:
> 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 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
--
LG Alex


*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH   Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*



More information about the DBIx-Class mailing list