DBIx::Class::Valiant::Validator::ResultSet - Verify a DBIC related resultset
package Example::Schema::Result::Person; use base 'Example::Schema::Result'; __PACKAGE__->load_components(qw/ Valiant::Result Core /); __PACKAGE__->table("person"); __PACKAGE__->add_columns( id => { data_type => 'bigint', is_nullable => 0, is_auto_increment => 1 }, username => { data_type => 'varchar', is_nullable => 0, size => 48 }, first_name => { data_type => 'varchar', is_nullable => 0, size => 24 }, last_name => { data_type => 'varchar', is_nullable => 0, size => 48 }, password => { data_type => 'varchar', is_nullable => 0, size => 64, }, ); __PACKAGE__->has_many( credit_cards => 'Example::Schema::Result::CreditCard', { 'foreign.person_id' => 'self.id' } ); __PACKAGE__->validates( credit_cards => ( result_set=>+{ validations=>1, skip_if_empty=>1, min=>2, max=>4 }, ) );
Validations on related resultsets. Used to apply constraints on the resultset as a whole (such as total number of rows) or to trigger running validations on any related row objects. Any errors from related resultsets will be added as sub errors on the parent result.
This validator supports the following attributes:
Boolean. Default is 0 ('false'). Used to trigger validations on row objects found inside the resultset. Please keep in mind this can be expensive if you have a lot of found rows (consider using limits and validating in chunks).
Please keep in mind these errors will be localized to the associated object, not on the current object.
Error message returned on the current object if we find any errors inside related objects. defaults to tag 'invalid_msg'.
Allows you to skip validations if the resultset is empty (has zero rows). Useful if you want to do validations only if there are rows found, such as when you have an optional relationship. Defaults to false.
The minimum or maximum number of rows that the resultset can contain. Optional.
Error messages associated with the 'min' or 'max' constraints. Defaults to 'too_few' or 'too_many' translation tags.
This validator supports the follow shortcut forms:
validates attribute => ( result_set => 1, ... );
Which is the same as:
validates attribute => ( result_set => { validations => 1, } );
Which is a shortcut when you wish to run validations on the related rows
This validator supports all the standard shared parameters: if, unless, message, strict, allow_undef, allow_blank.
if
unless
message
strict
allow_undef
allow_blank
Valiant, Valiant::Validator, Valiant::Validator::Each.
See Valiant
To install Valiant, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Valiant
CPAN shell
perl -MCPAN -e shell install Valiant
For more information on module installation, please visit the detailed CPAN module installation guide.