NAME
DBIx::Class::Valiant::Validator::ResultSet - Verify a DBIC related resultset
SYNOPSIS
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 },
)
);
DESCRIPTION
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.
ATTRIBUTES
This validator supports the following attributes:
validations
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.
invalid_msg
Error message returned on the current object if we find any errors inside related objects. defaults to tag 'invalid_msg'.
skip_if_empty
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.
min
max
The minimum or maximum number of rows that the resultset can contain. Optional.
too_few_msg
too_many_msg
Error messages associated with the 'min' or 'max' constraints. Defaults to 'too_few' or 'too_many' translation tags.
SHORTCUT FORM
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
GLOBAL PARAMETERS
This validator supports all the standard shared parameters: if
, unless
, message
, strict
, allow_undef
, allow_blank
.
SEE ALSO
Valiant, Valiant::Validator, Valiant::Validator::Each.
AUTHOR
See Valiant
COPYRIGHT & LICENSE
See Valiant