missed a couple things
[dbsrgits/DBIx-Class.git] / lib / SQL / Translator / Parser / DBIx / Class.pm
index 2d0bf00..92a6204 100644 (file)
@@ -1,4 +1,5 @@
-package SQL::Translator::Parser::DBIx::Class;
+package # hide from PAUSE 
+    SQL::Translator::Parser::DBIx::Class;
 
 # AUTHOR: Jess Robinson
 
@@ -21,7 +22,7 @@ use base qw(Exporter);
 # -------------------------------------------------------------------
 # parse($tr, $data)
 #
-# Note that $data, in the case of this parser, is unuseful.
+# Note that $data, in the case of this parser, is not useful.
 # We're working with DBIx::Class Schemas, not data streams.
 # -------------------------------------------------------------------
 sub parse {
@@ -72,7 +73,6 @@ sub parse {
         }
         $table->primary_key($source->primary_columns);
 
-
         my @rels = $source->relationships();
         foreach my $rel (@rels)
         {
@@ -80,7 +80,7 @@ sub parse {
             next if(!exists $rel_info->{attrs}{accessor} ||
                     $rel_info->{attrs}{accessor} eq 'multi');
             # Going by the accessor type isn't such a good idea (yes, I know
-            # I suggested it). I think the best way to tell if something's a
+            # I suggested it). I think the best way to tell if something is a
             # foreign key constraint is to assume if it doesn't include our
             # primaries then it is (dumb but it'll do). Ignore any rel cond
             # that isn't a straight hash, but get both sets of keys in full
@@ -92,15 +92,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,
-                                       );
+                );
             }
         }
     }