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. Any errors from related resultsets will be added as sub errors on the parent result.

NOTE: This gets added automatically for you if you setup accepts_nested on the parent object. So you shouldn't really ever need to use this code directly.

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'.

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