From: Simon Elliott Date: Tue, 28 Feb 2006 02:52:19 +0000 (+0000) Subject: Fix to foreign key sqlt generation X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2478970cd1dec7679985cb282afa0af420f517cc;p=dbsrgits%2FDBIx-Class-Historic.git Fix to foreign key sqlt generation --- diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index 2d0bf00..448c651 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -72,7 +72,6 @@ sub parse { } $table->primary_key($source->primary_columns); - my @rels = $source->relationships(); foreach my $rel (@rels) { @@ -92,15 +91,16 @@ sub parse { my $rel_table = $source->related_source($rel)->name; my $cond = (keys (%{$rel_info->{cond}}))[0]; my ($refkey) = $cond =~ /^\w+\.(\w+)$/; + my ($key) = $rel_info->{cond}->{$cond} =~ /^\w+\.(\w+)$/; if($rel_table && $refkey) { $table->add_constraint( type => 'foreign_key', - name => "fk_${rel}_id", - fields => $rel, + name => "fk_${key}", + fields => $key, reference_fields => $refkey, reference_table => $rel_table, - ); + ); } } }