schema-loader does multi-column FKs now, needs a bit of cleanup/refactor work
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / DB2.pm
index d0859a9..a6de578 100644 (file)
@@ -14,12 +14,11 @@ DBIx::Class::Schema::Loader::DB2 - DBIx::Class::Schema::Loader DB2 Implementatio
 
   # $loader is a DBIx::Class::Schema::Loader::DB2
   my $loader = DBIx::Class::Schema::Loader->new(
-    dsn       => "dbi:DB2:dbname",
-    user      => "myuser",
-    password  => "",
-    namespace => "Data",
-    schema    => "MYSCHEMA",
-    dropschema  => 0,
+    dsn         => "dbi:DB2:dbname",
+    user        => "myuser",
+    password    => "",
+    db_schema   => "MYSCHEMA",
+    drop_schema => 1,
   );
 
 =head1 DESCRIPTION
@@ -104,10 +103,20 @@ SQL
         if ($sth->execute(uc $table)) {
             while(my $res = $sth->fetchrow_arrayref()) {
                 my ($colcount, $other, $other_column, $column) =
-                    map { $_=lc; s/^\s+//; s/\s+$//; $_; } @$res;
-                next if $colcount != 1; # XXX no multi-col FK support yet
-                eval { $class->_belongs_to_many( $table, $column, $other,
-                  $other_column ) };
+                    map { lc } @$res;
+
+                my @self_cols = split(' ',$column);
+                my @other_cols = split(' ',$other_column);
+                if(@self_cols != $colcount || @other_cols != $colcount) {
+                    die "Column count discrepancy while getting rel info";
+                }
+
+                my %cond;
+                for(my $i = 0; $i < @self_cols; $i++) {
+                    $cond{$other_cols[$i]} = $self_cols[$i];
+                }
+
+                eval { $class->_belongs_to_many ($table, $other, \%cond); };
                 warn qq/\# belongs_to_many failed "$@"\n\n/
                   if $@ && $class->debug_loader;
             }