DBIx::Class::Validation doesn't seem to work

5 messages Options
Embed this post
Permalink
fREW Schmidt

DBIx::Class::Validation doesn't seem to work

Reply Threaded More More options
Print post
Permalink
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;


--
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/dbix-class@...
fREW Schmidt

Re: DBIx::Class::Validation doesn't seem to work

Reply Threaded More More options
Print post
Permalink
On Tue, Jul 7, 2009 at 5:31 PM, fREW Schmidt <[hidden email]> 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/dbix-class@...
Alexander Hartmaier

Re: Re: DBIx::Class::Validation doesn't seem to work

Reply Threaded More More options
Print post
Permalink
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 <[hidden email]> 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.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

_______________________________________________
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/dbix-class@...
Sergio Salvi

[PATCH] Re: DBIx::Class::Validation doesn't seem to work

Reply Threaded More More options
Print post
Permalink
In reply to this post by fREW Schmidt
All right, I've finally submitted my patch for the $row->update($fields) bug:

http://rt.cpan.org/Public/Bug/Display.html?id=47709

Sergio

On Wed, Jul 8, 2009 at 10:39 AM, fREW Schmidt<[hidden email]> wrote:

> Adding ->update() after the initial ->update($params) doesn't seem to do
> anything :-/
>
> On Tue, Jul 7, 2009 at 5:59 PM, Sergio Salvi <[hidden email]> wrote:
>>
>> Are you doing $row->update({ key => value }) ?
>>
>> Does calling $row->update() again solve your problem?
>>
>> Previous versions of the validation module had a bug where it wouldn't
>> validate fields if you called update($hashref) instead of using accessors to
>> set values and then just calling update(). It may have been fixed already. I
>> meant to report it as a bug, but ended up not doing it :(
>>
>> Sergio
>>
>> PS: I can't reply to the list from this email address...
>>
>> -----Original Message-----
>> From: fREW Schmidt <[hidden email]>
>>
>> Date: Tue, 7 Jul 2009 17:31:43
>> To: DBIx::Class user and developer list<[hidden email]>
>> Subject: [Dbix-class] DBIx::Class::Validation doesn't seem to work
>>
>>
>> _______________________________________________
>> 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/dbix-class@...
>>
>
>
>
> --
> 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/dbix-class@...
fREW Schmidt

Re: [PATCH] Re: DBIx::Class::Validation doesn't seem to work

Reply Threaded More More options
Print post
Permalink
Haha, you beat me to it!

On Wed, Jul 8, 2009 at 11:49 AM, Sergio Salvi <[hidden email]> wrote:
All right, I've finally submitted my patch for the $row->update($fields) bug:

http://rt.cpan.org/Public/Bug/Display.html?id=47709

Sergio

On Wed, Jul 8, 2009 at 10:39 AM, fREW Schmidt<[hidden email]> wrote:
> Adding ->update() after the initial ->update($params) doesn't seem to do
> anything :-/
>
> On Tue, Jul 7, 2009 at 5:59 PM, Sergio Salvi <[hidden email]> wrote:
>>
>> Are you doing $row->update({ key => value }) ?
>>
>> Does calling $row->update() again solve your problem?
>>
>> Previous versions of the validation module had a bug where it wouldn't
>> validate fields if you called update($hashref) instead of using accessors to
>> set values and then just calling update(). It may have been fixed already. I
>> meant to report it as a bug, but ended up not doing it :(
>>
>> Sergio
>>
>> PS: I can't reply to the list from this email address...
>>
>> -----Original Message-----
>> From: fREW Schmidt <[hidden email]>
>>
>> Date: Tue, 7 Jul 2009 17:31:43
>> To: DBIx::Class user and developer list<[hidden email]>
>> Subject: [Dbix-class] DBIx::Class::Validation doesn't seem to work
>>
>>
>> _______________________________________________
>> 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/dbix-class@...
>>
>
>
>
> --
> 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/dbix-class@...



--
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/dbix-class@...