[Bast-commits] r3344 - in branches/DBIx-Class-Schema-Loader/current: . lib/DBIx/Class/Schema/Loader lib/DBIx/Class/Schema/Loader/DBI t/lib

blblack at dev.catalyst.perl.org blblack at dev.catalyst.perl.org
Mon May 21 19:41:04 GMT 2007


Author: blblack
Date: 2007-05-21 19:41:04 +0100 (Mon, 21 May 2007)
New Revision: 3344

Modified:
   branches/DBIx-Class-Schema-Loader/current/
   branches/DBIx-Class-Schema-Loader/current/Changes
   branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm
   branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/RelBuilder.pm
   branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm
Log:
 r31109 at brandon-blacks-computer (orig r3316):  blblack | 2007-05-15 08:53:49 -0500
 
 Fix from Marc Espie for CREATE TABLE 'foo' for SQLite
 r31932 at brandon-blacks-computer (orig r3342):  ilmari | 2007-05-21 13:33:33 -0500
 fix multiple multi-column relations to the same table
 implementation by Brandon L Black, tests by me
 r31933 at brandon-blacks-computer (orig r3343):  blblack | 2007-05-21 13:37:38 -0500
 update Changes



Property changes on: branches/DBIx-Class-Schema-Loader/current
___________________________________________________________________
Name: svk:merge
   - bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/DBIx-Class-Schema-Loader:3197
   + bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/DBIx-Class-Schema-Loader:3343

Modified: branches/DBIx-Class-Schema-Loader/current/Changes
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/Changes	2007-05-21 18:37:38 UTC (rev 3343)
+++ branches/DBIx-Class-Schema-Loader/current/Changes	2007-05-21 18:41:04 UTC (rev 3344)
@@ -1,5 +1,8 @@
 Revision history for Perl extension DBIx::Class::Schema::Loader
 
+        - Relationship names for multiple multi-col rels between
+          the same table fixed by ilmari
+        - Fix from Marc Espie for CREATE TABLE 'foo' for SQLite
         - skip ^sqlite_ tables in SQLite (thanks chromatic)
 
 0.03999_01 Sat Apr 14 19:57:40 GMT 2007

Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm	2007-05-21 18:37:38 UTC (rev 3343)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm	2007-05-21 18:41:04 UTC (rev 3344)
@@ -62,7 +62,7 @@
     $sth->finish;
 
     # Cut "CREATE TABLE ( )" blabla...
-    $sql =~ /^[\w\s]+\((.*)\)$/si;
+    $sql =~ /^[\w\s']+\((.*)\)$/si;
     my $cols = $1;
 
     # strip single-line comments

Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/RelBuilder.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/RelBuilder.pm	2007-05-21 18:37:38 UTC (rev 3343)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/RelBuilder.pm	2007-05-21 18:41:04 UTC (rev 3344)
@@ -155,21 +155,11 @@
             $cond{$remote_cols->[$i]} = $local_cols->[$i];
         }
 
-        # If more than one rel between this pair of tables, use the
-        #  local col name(s) as the relname in the foreign source, instead
-        #  of the local table name.
         my $local_relname;
-        if($counters{$remote_moniker} > 1) {
-            $local_relname = $self->_inflect_plural(
-                lc($local_table) . q{_} . join(q{_}, @$local_cols)
-            );
-        } else {
-            $local_relname = $self->_inflect_plural(lc $local_table);
-        }
+        my $remote_relname;
 
-        # for single-column case, set the relname to the column name,
-        # to make filter accessors work
-        my $remote_relname;
+        # for single-column case, set the remote relname to the column
+        # name, to make filter accessors work
         if(scalar keys %cond == 1) {
             my ($col) = keys %cond;
             $remote_relname = $self->_inflect_singular($cond{$col});
@@ -178,6 +168,18 @@
             $remote_relname = $self->_inflect_singular(lc $remote_table);
         }
 
+        # If more than one rel between this pair of tables, use the local
+        # col names to distinguish
+        if($counters{$remote_moniker} > 1) {
+            my $colnames = q{_} . join(q{_}, @$local_cols);
+            $local_relname = $self->_inflect_plural(
+                lc($local_table) . $colnames
+            );
+            $remote_relname .= $colnames if keys %cond > 1;
+        } else {
+            $local_relname = $self->_inflect_plural(lc $local_table);
+        }
+
         my %rev_cond = reverse %cond;
 
         for (keys %rev_cond) {

Modified: branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm	2007-05-21 18:37:38 UTC (rev 3343)
+++ branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm	2007-05-21 18:41:04 UTC (rev 3344)
@@ -43,7 +43,7 @@
 sub run_tests {
     my $self = shift;
 
-    plan tests => 80;
+    plan tests => 88;
 
     $self->create();
 
@@ -302,6 +302,14 @@
         my $class22   = $classes->{loader_test22};
         my $rsobj22   = $conn->resultset($moniker22);
 
+        my $moniker25 = $monikers->{loader_test25};
+        my $class25   = $classes->{loader_test25};
+        my $rsobj25   = $conn->resultset($moniker25);
+
+        my $moniker26 = $monikers->{loader_test26};
+        my $class26   = $classes->{loader_test26};
+        my $rsobj26   = $conn->resultset($moniker26);
+
         isa_ok( $rsobj3, "DBIx::Class::ResultSet" );
         isa_ok( $rsobj4, "DBIx::Class::ResultSet" );
         isa_ok( $rsobj5, "DBIx::Class::ResultSet" );
@@ -316,6 +324,8 @@
         isa_ok( $rsobj20, "DBIx::Class::ResultSet" );
         isa_ok( $rsobj21, "DBIx::Class::ResultSet" );
         isa_ok( $rsobj22, "DBIx::Class::ResultSet" );
+        isa_ok( $rsobj25, "DBIx::Class::ResultSet" );
+        isa_ok( $rsobj26, "DBIx::Class::ResultSet" );
 
         # basic rel test
         my $obj4 = $rsobj4->find(123);
@@ -358,6 +368,22 @@
         
         # XXX test double-fk m:m 21 <- 22 -> 21
 
+        # test double multi-col fk 26 -> 25
+        my $obj26 = $rsobj26->find(33);
+
+        my $rs_rel25_one = $obj26->loader_test25_id_rel1;
+        isa_ok($rs_rel25_one, $class25);
+        is($rs_rel25_one->dat, 'x25');
+
+        my $rs_rel25_two = $obj26->loader_test25_id_rel2;
+        isa_ok($rs_rel25_two, $class25);
+        is($rs_rel25_two->dat, 'y25');
+
+        my $obj25 = $rsobj25->find(3,42);
+        my $rs_rel26 = $obj25->search_related('loader_test26_id_rel1s');
+        isa_ok($rs_rel26->first, $class26);
+        is($rs_rel26->first->id, 3);
+
         # from Chisel's tests...
         SKIP: {
             if($self->{vendor} =~ /sqlite/i) {
@@ -706,6 +732,32 @@
         q{ INSERT INTO loader_test22 (parent, child) VALUES (7,11)},
         q{ INSERT INTO loader_test22 (parent, child) VALUES (11,13)},
         q{ INSERT INTO loader_test22 (parent, child) VALUES (13,17)},
+
+	qq{
+            CREATE TABLE loader_test25 (
+                id1 INTEGER NOT NULL,
+                id2 INTEGER NOT NULL,
+                dat VARCHAR(8),
+                PRIMARY KEY (id1,id2)
+            ) $self->{innodb}
+        },
+
+        q{ INSERT INTO loader_test25 (id1,id2,dat) VALUES (33,5,'x25') },
+        q{ INSERT INTO loader_test25 (id1,id2,dat) VALUES (33,7,'y25') },
+        q{ INSERT INTO loader_test25 (id1,id2,dat) VALUES (3,42,'z25') },
+
+        qq{
+            CREATE TABLE loader_test26 (
+               id INTEGER NOT NULL PRIMARY KEY,
+               rel1 INTEGER NOT NULL,
+               rel2 INTEGER NOT NULL,
+               FOREIGN KEY (id, rel1) REFERENCES loader_test25 (id1, id2),
+               FOREIGN KEY (id, rel2) REFERENCES loader_test25 (id1, id2)
+            ) $self->{innodb}
+        },
+
+        q{ INSERT INTO loader_test26 (id,rel1,rel2) VALUES (33,5,7) },
+        q{ INSERT INTO loader_test26 (id,rel1,rel2) VALUES (3,42,42) },
     );
 
     my @statements_advanced = (
@@ -830,6 +882,8 @@
         loader_test18
         loader_test22
         loader_test21
+        loader_test26
+        loader_test25
     /;
 
     my @tables_advanced = qw/




More information about the Bast-commits mailing list