From: Justin Hunter Date: Tue, 21 Jun 2011 18:28:06 +0000 (-0700) Subject: better handling of FKs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4004eb306c3ab1e5d41c0c53dcf26acf05484fb4;p=dbsrgits%2FSQL-Translator-2.0-ish.git better handling of FKs --- diff --git a/lib/SQL/Translator/Object/Table.pm b/lib/SQL/Translator/Object/Table.pm index 8840f7c..0ee4121 100644 --- a/lib/SQL/Translator/Object/Table.pm +++ b/lib/SQL/Translator/Object/Table.pm @@ -111,6 +111,14 @@ class SQL::Translator::Object::Table extends SQL::Translator::Object is dirty { } around add_constraint(Constraint $constraint does coerce) { + if ($constraint->type eq 'FOREIGN KEY') { + my @columns = $constraint->get_columns; + die "There are no columns associated with this foreign key constraint." unless scalar @columns; + for my $column (@columns) { + die "Can't use column " . $column->name . ". It doesn't exist!" unless $self->exists_column($column); + } + die "Reference table " . $constraint->reference_table . " does not exist!" unless $self->schema->exists_table($constraint->reference_table); + } my $name = $constraint->name; if ($name eq '') { my $idx = 0;