remove needless alias
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Object / Constraint.pm
1 use MooseX::Declare;
2 class SQL::Translator::Object::Constraint extends SQL::Translator::Object {
3     use MooseX::Types::Moose qw(ArrayRef Bool HashRef Maybe Str Undef);
4     use SQL::Translator::Types qw(Column Table);
5
6     has 'table' => (
7         is => 'rw',
8         isa => Table,
9         required => 1,
10         weak_ref => 1,
11     );
12     
13     has 'name' => (
14         is => 'rw',
15         isa => Maybe[Str],
16         required => 1
17     );
18     
19     has 'columns' => (
20         traits => ['Hash'],
21         is => 'rw',
22         isa => HashRef[Column],
23         handles => {
24             exists_column => 'exists',
25             column_ids    => 'keys',
26             get_columns   => 'values',
27             get_column    => 'get',
28             add_column    => 'set',
29
30             ## compat
31             get_fields    => 'values',
32             fields        => 'keys',
33         },
34         default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
35     );
36     
37     has 'type' => (
38         is => 'rw',
39         isa => Str,
40         required => 1
41     );
42
43     has 'deferrable' => (
44         is => 'rw',
45         isa => Bool,
46         default => 1
47     );
48
49     has 'expression' => (
50         is => 'rw',
51         isa => Str,
52     );
53
54     has 'reference_table' => (
55         isa => Maybe[Str],
56         is => 'rw',
57     );
58
59     has 'reference_columns' => (
60         isa => ArrayRef | Undef,
61         is => 'rw',
62         auto_deref => 1
63     );
64
65     has 'match_type' => (
66         isa => Str,
67         is => 'rw'
68     );
69
70     around add_column(Column $column) { $self->$orig($column->name, $column) }
71
72     method reference_fields { $self->reference_columns }
73 }