2 class SQL::Translator::Object::Constraint extends SQL::Translator::Object {
3 use MooseX::Types::Moose qw(ArrayRef Bool HashRef Int Maybe Str Undef);
4 use MooseX::MultiMethods;
5 use SQL::Translator::Types qw(Column MatchType Table);
23 isa => HashRef[Column],
25 exists_column => 'exists',
27 get_columns => 'values',
30 clear_columns => 'clear',
32 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
38 predicate => 'has_type',
53 has 'reference_table' => (
58 has 'reference_columns' => (
62 reference_columns => 'elements',
63 add_reference_column => 'push',
65 default => sub { [] },
82 has 'on_delete' => ( is => 'rw', required => 0);
83 has 'on_update' => ( is => 'rw', required => 0);
85 around add_column(Column $column) {
86 if ($self->has_type && $self->type eq 'PRIMARY KEY') {
87 $column->is_primary_key(1);
89 $self->$orig($column->name, $column)
92 multi method order(Int $order) { $self->_order($order); }
94 my $order = $self->_order;
95 unless (defined $order && $order) {
96 my $tables = Tie::IxHash->new( map { $_->name => $_ } $self->schema->get_tables );
97 $order = $tables->Indices($self->name) || 0; $order++;
98 $self->_order($order);
103 method is_valid { return $self->has_type && scalar $self->column_ids ? 1 : undef }