NAME
DBIx::Class::Valiant::Validator::SetSize - 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 => (
set_size=>+{ skip_if_empty=>1, min=>2, max=>4 },
)
);
DESCRIPTION
Validations on related resultsets. This constrains minimum / maximum sizes on the set and permits optional sets (where the min/max is only applied when the set has entries).
ATTRIBUTES
This validator supports the following attributes:
skip_if_empty
Skip validations if the resultset is empty. In this context empty means that you have zero records. Probably not that useful; yhou might actually want 'skip_if_blank' instead.
skip_if_blank
Allows you to skip validations if the resultset is blank. In this context blank means that you have not prefetched the relationship or loaded it in any way. 'blank' is different from 'has none'. You might for example want to skip size validations if you have not prefetched the relationship.
min
max
The minimum or maximum number of rows that the resultset can contain. Optional (but I suspect you'd set at least one otherwise why bother with this constraint?
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,4], ... );
Which is the same as:
validates attribute => (
result_set => {
min => 1,
max => 4,
}
);
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