NAME
SQL::Translator::Schema::Constraint - SQL::Translator constraint object
SYNOPSIS
use SQL::Translator::Schema::Constraint;
my $constraint = SQL::Translator::Schema::Constraint->new(
name => 'foo',
fields => [ id ],
type => PRIMARY_KEY,
);
DESCRIPTION
SQL::Translator::Schema::Constraint
is the constraint object.
METHODS
new
Object constructor.
my $schema = SQL::Translator::Schema::Constraint->new(
table => $table, # table to which it belongs
type => 'foreign_key', # type of table constraint
name => 'fk_phone_id', # name of the constraint
fields => 'phone_id', # field in the referring table
reference_fields => 'phone_id', # referenced table
reference_table => 'phone', # referenced fields
match_type => 'full', # how to match
on_delete_do => 'cascade', # what to do on deletes
on_update_do => '', # what to do on updates
);
deferrable
Get or set the whether the constraint is deferrable. If not defined, then returns "1." The argument is evaluated by Perl for True or False, so the following are eqivalent:
$deferrable = $field->deferrable(0);
$deferrable = $field->deferrable('');
$deferrable = $field->deferrable('0');
expression
Gets and set the expression used in a CHECK constraint.
my $expression = $constraint->expression('...');
is_valid
Determine whether the constraint is valid or not.
my $ok = $constraint->is_valid;
fields
Gets and set the fields the constraint is on. Accepts a string, list or arrayref; returns an array or array reference. Will unique the field names and keep them in order by the first occurrence of a field name.
$constraint->fields('id');
$constraint->fields('id', 'name');
$constraint->fields( 'id, name' );
$constraint->fields( [ 'id', 'name' ] );
$constraint->fields( qw[ id name ] );
my @fields = $constraint->fields;
match_type
Get or set the constraint's match_type. Only valid values are "full" or "partial."
my $match_type = $constraint->match_type('FULL');
name
Get or set the constraint's name.
my $name = $constraint->name('foo');
options
Gets or adds to the constraints's options (e.g., "INITIALLY IMMEDIATE"). Returns an array or array reference.
$constraint->options('NORELY');
my @options = $constraint->options;
on_delete
Get or set the constraint's "on delete" action.
my $action = $constraint->on_delete('cascade');
on_update
Get or set the constraint's "on update" action.
my $action = $constraint->on_update('no action');
reference_fields
Gets and set the fields in the referred table. Accepts a string, list or arrayref; returns an array or array reference.
$constraint->reference_fields('id');
$constraint->reference_fields('id', 'name');
$constraint->reference_fields( 'id, name' );
$constraint->reference_fields( [ 'id', 'name' ] );
$constraint->reference_fields( qw[ id name ] );
my @reference_fields = $constraint->reference_fields;
reference_table
Get or set the table referred to by the constraint.
my $reference_table = $constraint->reference_table('foo');
table
Get or set the field's table object.
my $table = $field->table;
type
Get or set the constraint's type.
my $type = $constraint->type( PRIMARY_KEY );
AUTHOR
Ken Y. Clark <kclark@cpan.org>