comparison Lib/IMPL/SQL/Schema/Constraint/ForeignKey.pm @ 168:6148f89bb7bf

IMPL::SQL::Schema::Traits::Diff alfa version IMPL::lang added hash traits
author sourcer
date Mon, 16 May 2011 04:30:38 +0400
parents 1f7a6d762394
children 5c82eec23bb6
comparison
equal deleted inserted replaced
167:1f7a6d762394 168:6148f89bb7bf
13 public _direct property OnDelete => PROP_GET; 13 public _direct property OnDelete => PROP_GET;
14 public _direct property OnUpdate => PROP_GET; 14 public _direct property OnUpdate => PROP_GET;
15 } 15 }
16 16
17 __PACKAGE__->PassThroughArgs; 17 __PACKAGE__->PassThroughArgs;
18 __PACKAGE__->RegisterAlias('fk');
18 19
19 sub CTOR { 20 sub CTOR {
20 my ($this,%args) = @_; 21 my ($this,%args) = @_;
21 22
22 die new Eexception("Referenced table must be an instance of a table object") if not UNIVERSAL::isa($args{'referencedTable'},'IMPL::SQL::Schema::Table'); 23 die new Eexception("Referenced table must be an instance of a table object") if not UNIVERSAL::isa($args{'referencedTable'},'IMPL::SQL::Schema::Table');
24 die new Exception("Referenced columns must be a not empty list of columns") if not UNIVERSAL::isa($args{'referencedColumns'},'ARRAY') or not scalar(@{$args{'referencedColumns'}}); 25 die new Exception("Referenced columns must be a not empty list of columns") if not UNIVERSAL::isa($args{'referencedColumns'},'ARRAY') or not scalar(@{$args{'referencedColumns'}});
25 26
26 my @ReferencedColumns = map {IMPL::SQL::Schema::Constraint::ResolveColumn($args{'referencedTable'},$_)} @{$args{'referencedColumns'}}; 27 my @ReferencedColumns = map {IMPL::SQL::Schema::Constraint::ResolveColumn($args{'referencedTable'},$_)} @{$args{'referencedColumns'}};
27 my $ForeingPK = $args{'referencedTable'}->primaryKey or die new Exception('The referenced table doesn\'t have a primary key'); 28 my $ForeingPK = $args{'referencedTable'}->primaryKey or die new Exception('The referenced table doesn\'t have a primary key');
28 29
29 scalar (@ReferencedColumns) == scalar(@{$this->columns}) or die new Exception('A foreing key columns doesn\'t match refenced columns'); 30 scalar (@ReferencedColumns) == $this->columns->Count or die new Exception('A foreing key columns doesn\'t match refenced columns');
30 my @ColumnsCopy = @ReferencedColumns; 31 my @ColumnsCopy = @ReferencedColumns;
31 32
32 die new Exception('A foreing key columns doesn\'t match refenced columns') if grep { not $_->type->SameValue((shift @ColumnsCopy)->type)} @{$this->columns}; 33 die new Exception('A foreing key columns doesn\'t match refenced columns') if grep { not $_->type->SameValue((shift @ColumnsCopy)->type)} @{$this->columns};
33 34
34 @ColumnsCopy = @ReferencedColumns; 35 @ColumnsCopy = @ReferencedColumns;