[Bast-commits] r5555 - in DBIx-Class/0.08/branches/subquery: . t t/96multi_create t/lib t/lib/DBICTest t/lib/DBICTest/Schema

robkinyon at dev.catalyst.perl.org robkinyon at dev.catalyst.perl.org
Fri Feb 20 04:35:23 GMT 2009


Author: robkinyon
Date: 2009-02-20 04:35:22 +0000 (Fri, 20 Feb 2009)
New Revision: 5555

Added:
   DBIx-Class/0.08/branches/subquery/t/96multi_create/
   DBIx-Class/0.08/branches/subquery/t/96multi_create/cd_single.t
   DBIx-Class/0.08/branches/subquery/t/96multi_create_new.t
   DBIx-Class/0.08/branches/subquery/t/96multi_create_torture.t
   DBIx-Class/0.08/branches/subquery/t/lib/DBICTest/Schema/Artwork_to_Artist.pm
Modified:
   DBIx-Class/0.08/branches/subquery/
   DBIx-Class/0.08/branches/subquery/t/66relationship.t
   DBIx-Class/0.08/branches/subquery/t/96multi_create.t
   DBIx-Class/0.08/branches/subquery/t/lib/DBICTest/Schema.pm
   DBIx-Class/0.08/branches/subquery/t/lib/DBICTest/Schema/Artist.pm
   DBIx-Class/0.08/branches/subquery/t/lib/DBICTest/Schema/Artwork.pm
   DBIx-Class/0.08/branches/subquery/t/lib/sqlite.sql
Log:
 r5550 at rkinyon-lt-osx (orig r5549):  matthewt | 2009-02-19 23:31:50 -0500
  r27529 at agaton (orig r5341):  ribasushi | 2009-01-24 18:28:29 +0000
  small refactor
 
 r5551 at rkinyon-lt-osx (orig r5550):  matthewt | 2009-02-19 23:34:55 -0500
  r27530 at agaton (orig r5342):  ribasushi | 2009-01-24 18:39:02 +0000
  merge from branches/multicreate
 
 r5552 at rkinyon-lt-osx (orig r5551):  matthewt | 2009-02-19 23:35:02 -0500
  r27531 at agaton (orig r5343):  ribasushi | 2009-01-24 18:44:08 +0000
  that's it
 
 r5553 at rkinyon-lt-osx (orig r5552):  matthewt | 2009-02-19 23:35:07 -0500
  r27538 at agaton (orig r5350):  matthewt | 2009-01-25 22:27:59 +0000
  extract test
 



Property changes on: DBIx-Class/0.08/branches/subquery
___________________________________________________________________
Name: svk:merge
   - 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/branches/resultsetcolumn_custom_columns:5160
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/branches/sqla_1.50_compat:5414
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/trunk:5635
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class:32260
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class-CDBICompat:54993
9c88509d-e914-0410-b01c-b9530614cbfe:/vendor/DBIx-Class:31122
ab17426e-7cd3-4704-a2a2-80b7c0a611bb:/local/dbic_trunk:10772
bd5ac9a7-f185-4d95-9186-dbb8b392a572:/local/os/bast/DBIx-Class/0.08/trunk:2798
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/belongs_to_null_col_fix:5244
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/cdbicompat_integration:4160
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/complex_join_rels:4589
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/file_column:3920
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/on_disconnect_do:3694
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/oracle_sequence:4173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/parser_fk_index:4485
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/replication_dedux:4600
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/savepoints:4223
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/sqla_1.50_compat:5321
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/storage-ms-access:4142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/versioned_enhancements:4125
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/versioning:4578
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/trunk:5543
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-C3:318
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-current:2222
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-joins:173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-resultset:570
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/datetime:1716
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_compat:1855
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_unique_query_fixes:2142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/inflate:1988
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/many_to_many:2025
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/re_refactor_bugfix:1944
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/reorganize_tests:1827
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset-new-refactor:1766
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_2_electric_boogaloo:2175
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_cleanup:2102
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/sqlt_tests_refactor:2043
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/DBIx-Class:3606
fe160bb6-dc1c-0410-9f2b-d64a711b54a5:/local/DBIC-trunk-0.08:10510
   + 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/branches/resultsetcolumn_custom_columns:5160
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/branches/sqla_1.50_compat:5414
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/trunk:5635
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class:32260
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class-CDBICompat:54993
9c88509d-e914-0410-b01c-b9530614cbfe:/vendor/DBIx-Class:31122
ab17426e-7cd3-4704-a2a2-80b7c0a611bb:/local/dbic_trunk:10772
bd5ac9a7-f185-4d95-9186-dbb8b392a572:/local/os/bast/DBIx-Class/0.08/trunk:2798
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/belongs_to_null_col_fix:5244
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/cdbicompat_integration:4160
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/complex_join_rels:4589
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/file_column:3920
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/multi_stuff:5350
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/on_disconnect_do:3694
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/oracle_sequence:4173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/parser_fk_index:4485
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/replication_dedux:4600
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/savepoints:4223
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/sqla_1.50_compat:5321
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/storage-ms-access:4142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/versioned_enhancements:4125
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/versioning:4578
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/trunk:5552
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-C3:318
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-current:2222
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-joins:173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-resultset:570
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/datetime:1716
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_compat:1855
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_unique_query_fixes:2142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/inflate:1988
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/many_to_many:2025
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/re_refactor_bugfix:1944
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/reorganize_tests:1827
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset-new-refactor:1766
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_2_electric_boogaloo:2175
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_cleanup:2102
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/sqlt_tests_refactor:2043
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/DBIx-Class:3606
fe160bb6-dc1c-0410-9f2b-d64a711b54a5:/local/DBIC-trunk-0.08:10510

Modified: DBIx-Class/0.08/branches/subquery/t/66relationship.t
===================================================================
--- DBIx-Class/0.08/branches/subquery/t/66relationship.t	2009-02-20 04:35:19 UTC (rev 5554)
+++ DBIx-Class/0.08/branches/subquery/t/66relationship.t	2009-02-20 04:35:22 UTC (rev 5555)
@@ -268,33 +268,6 @@
 cmp_ok($artist->cds->count, '==', 0, "Correct new #cds for artist");
 cmp_ok($nartist->cds->count, '==', 2, "Correct new #cds for artist");
 
-my $new_artist = $schema->resultset("Artist")->new_result({ 'name' => 'Depeche Mode' });
-my $new_related_cd = $new_artist->new_related('cds', { 'title' => 'Leave in Silence', 'year' => 1982});
-eval {
-       $new_artist->insert;
-       $new_related_cd->insert;
-};
-is ($@, '', 'Staged insertion successful');
-ok($new_artist->in_storage, 'artist inserted');
-ok($new_related_cd->in_storage, 'new_related_cd inserted');
-
-TODO: {
-local $TODO = "TODOify for multicreate branch";
-my $new_cd = $schema->resultset("CD")->new_result({});
-my $new_related_artist = $new_cd->new_related('artist', { 'name' => 'Marillion',});
-lives_ok (
-    sub {
-       $new_related_artist->insert;
-       $new_cd->title( 'Misplaced Childhood' );
-       $new_cd->year ( 1985 );
-#       $new_cd->artist( $new_related_artist );  # For exact backward compatibility     # not sure what this means
-       $new_cd->insert;
-    },
-    'Reversed staged insertion successful'
-);
-ok($new_related_artist->in_storage, 'related artist inserted');
-ok($new_cd->in_storage, 'cd inserted');
-
 # check if is_foreign_key_constraint attr is set
 my $rs_normal = $schema->source('Track');
 my $relinfo = $rs_normal->relationship_info ('cd');
@@ -303,4 +276,3 @@
 my $rs_overridden = $schema->source('ForceForeign');
 my $relinfo_with_attr = $rs_overridden->relationship_info ('cd_3');
 cmp_ok($relinfo_with_attr->{attrs}{is_foreign_key_constraint}, '==', 0, "is_foreign_key_constraint defined for belongs_to relationships with attr.");
-}

Added: DBIx-Class/0.08/branches/subquery/t/96multi_create/cd_single.t
===================================================================
--- DBIx-Class/0.08/branches/subquery/t/96multi_create/cd_single.t	                        (rev 0)
+++ DBIx-Class/0.08/branches/subquery/t/96multi_create/cd_single.t	2009-02-20 04:35:22 UTC (rev 5555)
@@ -0,0 +1,35 @@
+use strict;
+use warnings;
+
+use Test::More qw(no_plan);
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+
+eval {
+  my $cd = $schema->resultset('CD')->first;
+  my $track = $schema->resultset('Track')->new_result({
+    cd => $cd,
+    position => 77,  # some day me might test this with Ordered
+    title => 'Multicreate rocks',
+    cd_single => {
+      artist => $cd->artist,
+      year => 2008,
+      title => 'Disemboweling MultiCreate',
+    },
+  });
+
+  isa_ok ($track, 'DBICTest::Track', 'Main Track object created');
+
+  $track->insert;
+
+  ok(1, 'created track');
+
+  is($track->title, 'Multicreate rocks', 'Correct Track title');
+
+  my $single = $track->cd_single;
+
+  ok($single->cdid, 'Got cdid');
+};

Modified: DBIx-Class/0.08/branches/subquery/t/96multi_create.t
===================================================================
--- DBIx-Class/0.08/branches/subquery/t/96multi_create.t	2009-02-20 04:35:19 UTC (rev 5554)
+++ DBIx-Class/0.08/branches/subquery/t/96multi_create.t	2009-02-20 04:35:22 UTC (rev 5555)
@@ -6,11 +6,11 @@
 use lib qw(t/lib);
 use DBICTest;
 
-plan tests => 89;
+plan tests => 85;
 
 my $schema = DBICTest->init_schema();
 
-# simple create + parent (the stuff $rs belongs_to)
+diag '* simple create + parent (the stuff $rs belongs_to)';
 eval {
   my $cd = $schema->resultset('CD')->create({
     artist => { 
@@ -26,8 +26,7 @@
 };
 diag $@ if $@;
 
-# same as above but the child and parent have no values,
-# except for an explicit parent pk
+diag '* same as above but the child and parent have no values, except for an explicit parent pk';
 eval {
   my $bm_rs = $schema->resultset('Bookmark');
   my $bookmark = $bm_rs->create({
@@ -49,7 +48,7 @@
 };
 diag $@ if $@;
 
-# create over > 1 levels of has_many create (A => { has_many => { B => has_many => C } } )
+diag '* create over > 1 levels of has_many create (A => { has_many => { B => has_many => C } } )';
 eval {
   my $artist = $schema->resultset('Artist')->first;
   my $cd = $artist->create_related (cds => {
@@ -83,7 +82,7 @@
   'create via update of multi relationships throws an exception'
 );
 
-# Create m2m while originating in the linker table
+diag '* Create m2m while originating in the linker table';
 eval {
   my $artist = $schema->resultset('Artist')->first;
   my $c2p = $schema->resultset('CD_to_Producer')->create ({
@@ -113,7 +112,19 @@
 };
 diag $@ if $@;
 
-# create over > 1 levels of might_have (A => { might_have => { B => has_many => C } } )
+diag (<<'DG');
+* Create over > 1 levels of might_have with multiple has_many and multiple m2m
+but starting at a has_many level
+
+CD -> has_many -> Tracks -> might have -> Single -> has_many -> Tracks
+                                               \
+                                                \-> has_many \
+                                                              --> CD2Producer
+                                                /-> has_many /
+                                               /
+                                          Producer
+DG
+
 eval {
   my $artist = $schema->resultset('Artist')->first;
   my $cd = $schema->resultset('CD')->create ({
@@ -122,7 +133,7 @@
     year => 2008,
     tracks => [
       {
-        position => 1,
+        position => 1, # some day me might test this with Ordered
         title => 'Off by one again',
       },
       {
@@ -141,7 +152,12 @@
               producer => {
                 name => 'K&R',
               }
-            }
+            },
+            {
+              producer => {
+                name => 'Don Knuth',
+              }
+            },
           ]
         },
       },
@@ -163,15 +179,83 @@
   is ($single->tracks->find ({ position => 1})->title, 'The dereferencer', 'Correct 1st track title');
   is ($single->tracks->find ({ position => 2})->title, 'The dereferencer II', 'Correct 2nd track title');
 
-  is ($single->cd_to_producer->count, 1, 'One producer created with the single cd');
-  is ($single->cd_to_producer->first->producer->name, 'K&R', 'Producer name correct');
+  is ($single->cd_to_producer->count, 2, 'Two producers created for the single cd');
+  is_deeply (
+    [ sort map { $_->producer->name } ($single->cd_to_producer->all) ],
+    ['Don Knuth', 'K&R'],
+    'Producers named correctly',
+  );
 };
 diag $@ if $@;
 
-TODO: {
-local $TODO = "Todoify for multicreate branch";
-# test might_have again but with a PK == FK in the middle (obviously not specified)
+diag (<<'DG');
+* Same as above but starting at the might_have directly
+
+Track -> might have -> Single -> has_many -> Tracks
+                           \
+                            \-> has_many \
+                                          --> CD2Producer
+                            /-> has_many /
+                           /
+                       Producer
+DG
+
 eval {
+  my $cd = $schema->resultset('CD')->first;
+  my $track = $schema->resultset('Track')->create ({
+    cd => $cd,
+    position => 77,  # some day me might test this with Ordered
+    title => 'Multicreate rocks',
+    cd_single => {
+      artist => $cd->artist,
+      year => 2008,
+      title => 'Disemboweling MultiCreate',
+      tracks => [
+        { title => 'Why does mst write this way', position => 1 },
+        { title => 'Chainsaw celebration', position => 2 },
+        { title => 'Purl cleans up', position => 3 },
+      ],
+      cd_to_producer => [
+        {
+          producer => {
+            name => 'mst',
+          }
+        },
+        {
+          producer => {
+            name => 'castaway',
+          }
+        },
+        {
+          producer => {
+            name => 'theorbtwo',
+          }
+        },
+      ]
+    },
+  });
+
+  isa_ok ($track, 'DBICTest::Track', 'Main Track object created');
+  is ($track->title, 'Multicreate rocks', 'Correct Track title');
+
+  my $single = $track->cd_single;
+  isa_ok ($single, 'DBICTest::CD', 'Created a single with the track');
+  is ($single->tracks->count, 3, '3 tracks on single CD');
+  is ($single->tracks->find ({ position => 1})->title, 'Why does mst write this way', 'Correct 1st track title');
+  is ($single->tracks->find ({ position => 2})->title, 'Chainsaw celebration', 'Correct 2nd track title');
+  is ($single->tracks->find ({ position => 3})->title, 'Purl cleans up', 'Correct 3rd track title');
+
+  is ($single->cd_to_producer->count, 3, '3 producers created for the single cd');
+  is_deeply (
+    [ sort map { $_->producer->name } ($single->cd_to_producer->all) ],
+    ['castaway', 'mst', 'theorbtwo'],
+    'Producers named correctly',
+  );
+};
+diag $@ if $@;
+
+diag '* Test might_have again but with a PK == FK in the middle (obviously not specified)';
+eval {
   my $artist = $schema->resultset('Artist')->first;
   my $cd = $schema->resultset('CD')->create ({
     artist => $artist,
@@ -199,7 +283,6 @@
     'Images named correctly in objects',
   );
 
-
   my $artwork = $schema->resultset('Artwork')->search (
     { 'cd.title' => 'Music to code by at twilight' },
     { join => 'cd' },
@@ -215,7 +298,7 @@
 };
 diag $@ if $@;
 
-# test might_have again but with just a PK and FK (neither specified) in the mid-table
+diag '* Test might_have again but with just a PK and FK (neither specified) in the mid-table';
 eval {
   my $cd = $schema->resultset('CD')->first;
   my $track = $schema->resultset ('Track')->create ({
@@ -260,10 +343,60 @@
   );
 };
 diag $@ if $@;
-}
 
-# nested find_or_create
+diag (<<'DG');
+* Test a multilevel might-have with a PK == FK in the might_have/has_many table
+
+CD -> might have -> Artwork
+                       \
+                        \-> has_many \
+                                      --> Artwork_to_Artist
+                        /-> has_many /
+                       /
+                     Artist
+DG
+
 eval {
+  my $someartist = $schema->resultset('Artist')->first;
+  my $cd = $schema->resultset('CD')->create ({
+    artist => $someartist,
+    title => 'Music to code by until the cows come home',
+    year => 2008,
+    artwork => {
+      artwork_to_artist => [
+        { artist => { name => 'cowboy joe' } },
+        { artist => { name => 'billy the kid' } },
+      ],
+    },
+  });
+
+  isa_ok ($cd, 'DBICTest::CD', 'Main CD object created');
+  is ($cd->title, 'Music to code by until the cows come home', 'Correct CD title');
+
+  my $art_obj = $cd->artwork;
+  ok ($art_obj->has_column_loaded ('cd_id'), 'PK/FK present on artwork object');
+  is ($art_obj->artists->count, 2, 'Correct artwork creator count via the new object');
+  is_deeply (
+    [ sort $art_obj->artists->get_column ('name')->all ],
+    [ 'billy the kid', 'cowboy joe' ],
+    'Artists named correctly when queried via object',
+  );
+
+  my $artwork = $schema->resultset('Artwork')->search (
+    { 'cd.title' => 'Music to code by until the cows come home' },
+    { join => 'cd' },
+  )->single;
+  is ($artwork->artists->count, 2, 'Correct artwork creator count via a new search');
+  is_deeply (
+    [ sort $artwork->artists->get_column ('name')->all ],
+    [ 'billy the kid', 'cowboy joe' ],
+    'Artists named correctly queried via a new search',
+  );
+};
+diag $@ if $@;
+
+diag '* Nested find_or_create';
+eval {
   my $newartist2 = $schema->resultset('Artist')->find_or_create({ 
     name => 'Fred 3',
     cds => [
@@ -277,7 +410,7 @@
 };
 diag $@ if $@;
 
-# multiple same level has_many create
+diag '* Multiple same level has_many create';
 eval {
   my $artist2 = $schema->resultset('Artist')->create({
     name => 'Fred 4',
@@ -299,7 +432,7 @@
 };
 diag $@ if $@;
 
-# first create_related pass
+diag '* First create_related pass';
 eval {
 	my $artist = $schema->resultset('Artist')->first;
 	
@@ -333,7 +466,7 @@
 };
 diag $@ if $@;
 
-# second create_related with same arguments
+diag '* second create_related with same arguments';
 eval {
 	my $artist = $schema->resultset('Artist')->first;
 	
@@ -370,7 +503,7 @@
 };
 diag $@ if $@;
 
-# create of parents of a record linker table
+diag '* create of parents of a record linker table';
 eval {
   my $cdp = $schema->resultset('CD_to_Producer')->create({
     cd => { artist => 1, title => 'foo', year => 2000 },
@@ -380,6 +513,8 @@
 };
 diag $@ if $@;
 
+TODO: {
+local $TODO = 'Next 2 evals are NOT supposed to work, jnaps code will be torn to bits in another branch';
 #SPECIAL_CASE
 eval {
   my $kurt_cobain = { name => 'Kurt Cobain' };
@@ -417,9 +552,10 @@
   is($a->cds && $a->cds->first->title, 'The Wall', 'CD insertion ok');
 };
 diag $@ if $@;
+}
 
-## Create foreign key col obj including PK
-## See test 20 in 66relationships.t
+
+diag '* Create foreign key col obj including PK (See test 20 in 66relationships.t)';
 eval {
   my $new_cd_hashref = { 
     cdid => 27, 
@@ -447,7 +583,7 @@
 };
 is($@, '', 'new cd created without clash on related artist');
 
-# Make sure exceptions from errors in created rels propogate
+diag '* Make sure exceptions from errors in created rels propogate';
 eval {
     my $t = $schema->resultset("Track")->new({ cd => { artist => undef } });
     #$t->cd($t->new_related('cd', { artist => undef } ) );
@@ -456,7 +592,7 @@
 };
 like($@, qr/cd.artist may not be NULL/, "Exception propogated properly");
 
-# Test multi create over many_to_many
+diag '* Test multi create over many_to_many';
 eval {
   $schema->resultset('CD')->create ({
     artist => {
@@ -475,217 +611,4 @@
   is ($m2m_cd->first->producers->first->name, 'Cowboy Neal', 'Correct producer row created');
 };
 
-# and some insane multicreate 
-# (should work, despite the fact that no one will probably use it this way)
-
-# first count how many rows do we initially have
-my $counts;
-$counts->{$_} = $schema->resultset($_)->count for qw/Artist CD Genre Producer Tag/;
-
-# do the crazy create
-eval {
-  $schema->resultset('CD')->create ({
-    artist => {
-      name => 'james',
-    },
-    title => 'Greatest hits 1',
-    year => '2012',
-    genre => {
-      name => '"Greatest" collections',
-    },
-    tags => [
-      { tag => 'A' },
-      { tag => 'B' },
-    ],
-    cd_to_producer => [
-      {
-        producer => {
-          name => 'bob',
-          producer_to_cd => [
-            {
-              cd => { 
-                artist => {
-                  name => 'lars',
-                  cds => [
-                    {
-                      title => 'Greatest hits 2',
-                      year => 2012,
-                      genre => {
-                        name => '"Greatest" collections',
-                      },
-                      tags => [
-                        { tag => 'A' },
-                        { tag => 'B' },
-                      ],
-                      # This cd is created via artist so it doesn't know about producers
-                      cd_to_producer => [
-                        # if we specify 'bob' here things bomb
-                        # as the producer attached to Greatest Hits 1 is
-                        # already created, but not yet inserted.
-                        # Maybe this can be fixed, but things are hairy
-                        # enough already.
-                        #
-                        #{ producer => { name => 'bob' } },
-                        { producer => { name => 'paul' } },
-                        { producer => {
-                          name => 'flemming',
-                          producer_to_cd => [
-                            { cd => {
-                              artist => {
-                                name => 'kirk',
-                                cds => [
-                                  {
-                                    title => 'Greatest hits 3',
-                                    year => 2012,
-                                    genre => {
-                                      name => '"Greatest" collections',
-                                    },
-                                    tags => [
-                                      { tag => 'A' },
-                                      { tag => 'B' },
-                                    ],
-                                  },
-                                  {
-                                    title => 'Greatest hits 4',
-                                    year => 2012,
-                                    genre => {
-                                      name => '"Greatest" collections2',
-                                    },
-                                    tags => [
-                                      { tag => 'A' },
-                                      { tag => 'B' },
-                                    ],
-                                  },
-                                ],
-                              },
-                              title => 'Greatest hits 5',
-                              year => 2013,
-                              genre => {
-                                name => '"Greatest" collections2',
-                              },
-                            }},
-                          ],
-                        }},
-                      ],
-                    },
-                  ],
-                },
-                title => 'Greatest hits 6',
-                year => 2012,
-                genre => {
-                  name => '"Greatest" collections',
-                },
-                tags => [
-                  { tag => 'A' },
-                  { tag => 'B' },
-                ],
-              },
-            },
-            {
-              cd => { 
-                artist => {
-                  name => 'lars',    # should already exist
-                  # even though the artist 'name' is not uniquely constrained
-                  # find_or_create will arguably DWIM 
-                },
-                title => 'Greatest hits 7',
-                year => 2013,
-              },
-            },
-          ],
-        },
-      },
-    ],
-  });
-
-  is ($schema->resultset ('Artist')->count, $counts->{Artist} + 3, '3 new artists created');
-  is ($schema->resultset ('Genre')->count, $counts->{Genre} + 2, '2 additional genres created');
-  is ($schema->resultset ('Producer')->count, $counts->{Producer} + 3, '3 new producer');
-  is ($schema->resultset ('CD')->count, $counts->{CD} + 7, '7 new CDs');
-  is ($schema->resultset ('Tag')->count, $counts->{Tag} + 10, '10 new Tags');
-
-  my $cd_rs = $schema->resultset ('CD')
-    ->search ({ title => { -like => 'Greatest hits %' }}, { order_by => 'title'} );
-  is ($cd_rs->count, 7, '7 greatest hits created');
-
-  my $cds_2012 = $cd_rs->search ({ year => 2012});
-  is ($cds_2012->count, 5, '5 CDs created in 2012');
-
-  is (
-    $cds_2012->search(
-      { 'tags.tag' => { -in => [qw/A B/] } },
-      { join => 'tags', group_by => 'me.cdid' }
-    ),
-    5,
-    'All 10 tags were pairwise distributed between 5 year-2012 CDs'
-  );
-
-  my $paul_prod = $cd_rs->search (
-    { 'producer.name' => 'paul'},
-    { join => { cd_to_producer => 'producer' } }
-  );
-  is ($paul_prod->count, 1, 'Paul had 1 production');
-  my $pauls_cd = $paul_prod->single;
-  is ($pauls_cd->cd_to_producer->count, 2, 'Paul had one co-producer');
-  is (
-    $pauls_cd->search_related ('cd_to_producer',
-      { 'producer.name' => 'flemming'},
-      { join => 'producer' }
-    )->count,
-    1,
-    'The second producer is flemming',
-  );
-
-  my $kirk_cds = $cd_rs->search ({ 'artist.name' => 'kirk' }, { join => 'artist' });
-  is ($kirk_cds, 3, 'Kirk had 3 CDs');
-  is (
-    $kirk_cds->search (
-      { 'cd_to_producer.cd' => { '!=', undef } },
-      { join => 'cd_to_producer' },
-    ),
-    1,
-    'Kirk had a producer only on one cd',
-  );
-
-  my $lars_cds = $cd_rs->search ({ 'artist.name' => 'lars' }, { join => 'artist' });
-  is ($lars_cds->count, 3, 'Lars had 3 CDs');
-  is (
-    $lars_cds->search (
-      { 'cd_to_producer.cd' => undef },
-      { join => 'cd_to_producer' },
-    ),
-    0,
-    'Lars always had a producer',
-  );
-  is (
-    $lars_cds->search_related ('cd_to_producer',
-      { 'producer.name' => 'flemming'},
-      { join => 'producer' }
-    )->count,
-    1,
-    'Lars produced 1 CD with flemming',
-  );
-  is (
-    $lars_cds->search_related ('cd_to_producer',
-      { 'producer.name' => 'bob'},
-      { join => 'producer' }
-    )->count,
-    2,
-    'Lars produced 2 CDs with bob',
-  );
-
-  my $bob_prod = $cd_rs->search (
-    { 'producer.name' => 'bob'},
-    { join => { cd_to_producer => 'producer' } }
-  );
-  is ($bob_prod->count, 3, 'Bob produced a total of 3 CDs');
-
-  is (
-    $bob_prod->search ({ 'artist.name' => 'james' }, { join => 'artist' })->count,
-    1,
-    "Bob produced james' only CD",
-  );
-};
-diag $@ if $@;
-
 1;

Added: DBIx-Class/0.08/branches/subquery/t/96multi_create_new.t
===================================================================
--- DBIx-Class/0.08/branches/subquery/t/96multi_create_new.t	                        (rev 0)
+++ DBIx-Class/0.08/branches/subquery/t/96multi_create_new.t	2009-02-20 04:35:22 UTC (rev 5555)
@@ -0,0 +1,49 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest;
+
+plan 'no_plan';
+
+my $schema = DBICTest->init_schema();
+
+# Test various new() invocations - this is all about backcompat, making 
+# sure that insert() still works as expected by legacy code.
+#
+# What we essentially do is multi-instantiate objects, making sure nothing
+# gets inserted. Then we add some more objects to the mix either via
+# new_related() or by setting an accessor directly (or both) - again
+# expecting no inserts. Then after calling insert() on the starter object
+# we expect everything supplied to new() to get inserted, as well as any
+# relations whose PK's are necessary to complete the objects supplied
+# to new(). All other objects should be insert()able afterwards too.
+
+
+my $new_artist = $schema->resultset("Artist")->new_result({ 'name' => 'Depeche Mode' });
+my $new_related_cd = $new_artist->new_related('cds', { 'title' => 'Leave in Silence', 'year' => 1982});
+eval {
+       $new_artist->insert;
+       $new_related_cd->insert;
+};
+is ($@, '', 'Staged insertion successful');
+ok($new_artist->in_storage, 'artist inserted');
+ok($new_related_cd->in_storage, 'new_related_cd inserted');
+
+
+my $new_cd = $schema->resultset("CD")->new_result({});
+my $new_related_artist = $new_cd->new_related('artist', { 'name' => 'Marillion',});
+lives_ok (
+    sub {
+       $new_related_artist->insert;
+       $new_cd->title( 'Misplaced Childhood' );
+       $new_cd->year ( 1985 );
+       $new_cd->artist( $new_related_artist );  # For exact backward compatibility
+       $new_cd->insert;
+    },
+    'Reversed staged insertion successful'
+);
+ok($new_related_artist->in_storage, 'related artist inserted');
+ok($new_cd->in_storage, 'cd inserted');

Added: DBIx-Class/0.08/branches/subquery/t/96multi_create_torture.t
===================================================================
--- DBIx-Class/0.08/branches/subquery/t/96multi_create_torture.t	                        (rev 0)
+++ DBIx-Class/0.08/branches/subquery/t/96multi_create_torture.t	2009-02-20 04:35:22 UTC (rev 5555)
@@ -0,0 +1,226 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest;
+
+plan tests => 19;
+
+# an insane multicreate 
+# (should work, despite the fact that no one will probably use it this way)
+
+my $schema = DBICTest->init_schema();
+
+# first count how many rows do we initially have
+my $counts;
+$counts->{$_} = $schema->resultset($_)->count for qw/Artist CD Genre Producer Tag/;
+
+# do the crazy create
+eval {
+  $schema->resultset('CD')->create ({
+    artist => {
+      name => 'james',
+    },
+    title => 'Greatest hits 1',
+    year => '2012',
+    genre => {
+      name => '"Greatest" collections',
+    },
+    tags => [
+      { tag => 'A' },
+      { tag => 'B' },
+    ],
+    cd_to_producer => [
+      {
+        producer => {
+          name => 'bob',
+          producer_to_cd => [
+            {
+              cd => { 
+                artist => {
+                  name => 'lars',
+                  cds => [
+                    {
+                      title => 'Greatest hits 2',
+                      year => 2012,
+                      genre => {
+                        name => '"Greatest" collections',
+                      },
+                      tags => [
+                        { tag => 'A' },
+                        { tag => 'B' },
+                      ],
+                      # This cd is created via artist so it doesn't know about producers
+                      cd_to_producer => [
+                        # if we specify 'bob' here things bomb
+                        # as the producer attached to Greatest Hits 1 is
+                        # already created, but not yet inserted.
+                        # Maybe this can be fixed, but things are hairy
+                        # enough already.
+                        #
+                        #{ producer => { name => 'bob' } },
+                        { producer => { name => 'paul' } },
+                        { producer => {
+                          name => 'flemming',
+                          producer_to_cd => [
+                            { cd => {
+                              artist => {
+                                name => 'kirk',
+                                cds => [
+                                  {
+                                    title => 'Greatest hits 3',
+                                    year => 2012,
+                                    genre => {
+                                      name => '"Greatest" collections',
+                                    },
+                                    tags => [
+                                      { tag => 'A' },
+                                      { tag => 'B' },
+                                    ],
+                                  },
+                                  {
+                                    title => 'Greatest hits 4',
+                                    year => 2012,
+                                    genre => {
+                                      name => '"Greatest" collections2',
+                                    },
+                                    tags => [
+                                      { tag => 'A' },
+                                      { tag => 'B' },
+                                    ],
+                                  },
+                                ],
+                              },
+                              title => 'Greatest hits 5',
+                              year => 2013,
+                              genre => {
+                                name => '"Greatest" collections2',
+                              },
+                            }},
+                          ],
+                        }},
+                      ],
+                    },
+                  ],
+                },
+                title => 'Greatest hits 6',
+                year => 2012,
+                genre => {
+                  name => '"Greatest" collections',
+                },
+                tags => [
+                  { tag => 'A' },
+                  { tag => 'B' },
+                ],
+              },
+            },
+            {
+              cd => { 
+                artist => {
+                  name => 'lars',    # should already exist
+                  # even though the artist 'name' is not uniquely constrained
+                  # find_or_create will arguably DWIM 
+                },
+                title => 'Greatest hits 7',
+                year => 2013,
+              },
+            },
+          ],
+        },
+      },
+    ],
+  });
+
+  is ($schema->resultset ('Artist')->count, $counts->{Artist} + 3, '3 new artists created');
+  is ($schema->resultset ('Genre')->count, $counts->{Genre} + 2, '2 additional genres created');
+  is ($schema->resultset ('Producer')->count, $counts->{Producer} + 3, '3 new producer');
+  is ($schema->resultset ('CD')->count, $counts->{CD} + 7, '7 new CDs');
+  is ($schema->resultset ('Tag')->count, $counts->{Tag} + 10, '10 new Tags');
+
+  my $cd_rs = $schema->resultset ('CD')
+    ->search ({ title => { -like => 'Greatest hits %' }}, { order_by => 'title'} );
+  is ($cd_rs->count, 7, '7 greatest hits created');
+
+  my $cds_2012 = $cd_rs->search ({ year => 2012});
+  is ($cds_2012->count, 5, '5 CDs created in 2012');
+
+  is (
+    $cds_2012->search(
+      { 'tags.tag' => { -in => [qw/A B/] } },
+      { join => 'tags', group_by => 'me.cdid' }
+    ),
+    5,
+    'All 10 tags were pairwise distributed between 5 year-2012 CDs'
+  );
+
+  my $paul_prod = $cd_rs->search (
+    { 'producer.name' => 'paul'},
+    { join => { cd_to_producer => 'producer' } }
+  );
+  is ($paul_prod->count, 1, 'Paul had 1 production');
+  my $pauls_cd = $paul_prod->single;
+  is ($pauls_cd->cd_to_producer->count, 2, 'Paul had one co-producer');
+  is (
+    $pauls_cd->search_related ('cd_to_producer',
+      { 'producer.name' => 'flemming'},
+      { join => 'producer' }
+    )->count,
+    1,
+    'The second producer is flemming',
+  );
+
+  my $kirk_cds = $cd_rs->search ({ 'artist.name' => 'kirk' }, { join => 'artist' });
+  is ($kirk_cds, 3, 'Kirk had 3 CDs');
+  is (
+    $kirk_cds->search (
+      { 'cd_to_producer.cd' => { '!=', undef } },
+      { join => 'cd_to_producer' },
+    ),
+    1,
+    'Kirk had a producer only on one cd',
+  );
+
+  my $lars_cds = $cd_rs->search ({ 'artist.name' => 'lars' }, { join => 'artist' });
+  is ($lars_cds->count, 3, 'Lars had 3 CDs');
+  is (
+    $lars_cds->search (
+      { 'cd_to_producer.cd' => undef },
+      { join => 'cd_to_producer' },
+    ),
+    0,
+    'Lars always had a producer',
+  );
+  is (
+    $lars_cds->search_related ('cd_to_producer',
+      { 'producer.name' => 'flemming'},
+      { join => 'producer' }
+    )->count,
+    1,
+    'Lars produced 1 CD with flemming',
+  );
+  is (
+    $lars_cds->search_related ('cd_to_producer',
+      { 'producer.name' => 'bob'},
+      { join => 'producer' }
+    )->count,
+    2,
+    'Lars produced 2 CDs with bob',
+  );
+
+  my $bob_prod = $cd_rs->search (
+    { 'producer.name' => 'bob'},
+    { join => { cd_to_producer => 'producer' } }
+  );
+  is ($bob_prod->count, 3, 'Bob produced a total of 3 CDs');
+
+  is (
+    $bob_prod->search ({ 'artist.name' => 'james' }, { join => 'artist' })->count,
+    1,
+    "Bob produced james' only CD",
+  );
+};
+diag $@ if $@;
+
+1;

Modified: DBIx-Class/0.08/branches/subquery/t/lib/DBICTest/Schema/Artist.pm
===================================================================
--- DBIx-Class/0.08/branches/subquery/t/lib/DBICTest/Schema/Artist.pm	2009-02-20 04:35:19 UTC (rev 5554)
+++ DBIx-Class/0.08/branches/subquery/t/lib/DBICTest/Schema/Artist.pm	2009-02-20 04:35:22 UTC (rev 5555)
@@ -53,6 +53,12 @@
   { cascade_copy => 0 } # this would *so* not make sense
 );
 
+__PACKAGE__->has_many(
+    artist_to_artwork => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id'
+);
+__PACKAGE__->many_to_many('artworks', 'artist_to_artwork', 'artwork');
+
+
 sub sqlt_deploy_hook {
   my ($self, $sqlt_table) = @_;
 

Modified: DBIx-Class/0.08/branches/subquery/t/lib/DBICTest/Schema/Artwork.pm
===================================================================
--- DBIx-Class/0.08/branches/subquery/t/lib/DBICTest/Schema/Artwork.pm	2009-02-20 04:35:19 UTC (rev 5554)
+++ DBIx-Class/0.08/branches/subquery/t/lib/DBICTest/Schema/Artwork.pm	2009-02-20 04:35:22 UTC (rev 5555)
@@ -1,4 +1,4 @@
-package # hide from PAUSE 
+package # hide from PAUSE
     DBICTest::Schema::Artwork;
 
 use base qw/DBIx::Class::Core/;
@@ -13,4 +13,7 @@
 __PACKAGE__->belongs_to('cd', 'DBICTest::Schema::CD', 'cd_id');
 __PACKAGE__->has_many('images', 'DBICTest::Schema::Image', 'artwork_id');
 
+__PACKAGE__->has_many('artwork_to_artist', 'DBICTest::Schema::Artwork_to_Artist', 'artwork_cd_id');
+__PACKAGE__->many_to_many('artists', 'artwork_to_artist', 'artist');
+
 1;

Added: DBIx-Class/0.08/branches/subquery/t/lib/DBICTest/Schema/Artwork_to_Artist.pm
===================================================================
--- DBIx-Class/0.08/branches/subquery/t/lib/DBICTest/Schema/Artwork_to_Artist.pm	                        (rev 0)
+++ DBIx-Class/0.08/branches/subquery/t/lib/DBICTest/Schema/Artwork_to_Artist.pm	2009-02-20 04:35:22 UTC (rev 5555)
@@ -0,0 +1,21 @@
+package # hide from PAUSE
+    DBICTest::Schema::Artwork_to_Artist;
+
+use base qw/DBIx::Class::Core/;
+
+__PACKAGE__->table('artwork_to_artist');
+__PACKAGE__->add_columns(
+  'artwork_cd_id' => {
+    data_type => 'integer',
+    is_foreign_key => 1,
+  },
+  'artist_id' => {
+    data_type => 'integer',
+    is_foreign_key => 1,
+  },
+);
+__PACKAGE__->set_primary_key(qw/artwork_cd_id artist_id/);
+__PACKAGE__->belongs_to('artwork', 'DBICTest::Schema::Artwork', 'artwork_cd_id');
+__PACKAGE__->belongs_to('artist', 'DBICTest::Schema::Artist', 'artist_id');
+
+1;

Modified: DBIx-Class/0.08/branches/subquery/t/lib/DBICTest/Schema.pm
===================================================================
--- DBIx-Class/0.08/branches/subquery/t/lib/DBICTest/Schema.pm	2009-02-20 04:35:19 UTC (rev 5554)
+++ DBIx-Class/0.08/branches/subquery/t/lib/DBICTest/Schema.pm	2009-02-20 04:35:22 UTC (rev 5555)
@@ -22,6 +22,7 @@
   { 'DBICTest::Schema' => [qw/
     LinerNotes
     Artwork
+    Artwork_to_Artist
     Image
     Lyrics
     LyricVersion

Modified: DBIx-Class/0.08/branches/subquery/t/lib/sqlite.sql
===================================================================
--- DBIx-Class/0.08/branches/subquery/t/lib/sqlite.sql	2009-02-20 04:35:19 UTC (rev 5554)
+++ DBIx-Class/0.08/branches/subquery/t/lib/sqlite.sql	2009-02-20 04:35:22 UTC (rev 5555)
@@ -1,6 +1,6 @@
 -- 
 -- Created by SQL::Translator::Producer::SQLite
--- Created on Sat Jan 17 19:40:47 2009
+-- Created on Sat Jan 24 19:42:15 2009
 -- 
 BEGIN TRANSACTION;
 
@@ -38,6 +38,18 @@
 CREATE INDEX cd_artwork_idx_cd_id_cd_artwor ON cd_artwork (cd_id);
 
 --
+-- Table: artwork_to_artist
+--
+CREATE TABLE artwork_to_artist (
+  artwork_cd_id integer NOT NULL,
+  artist_id integer NOT NULL,
+  PRIMARY KEY (artwork_cd_id, artist_id)
+);
+
+CREATE INDEX artwork_to_artist_idx_artist_id_artwork_to_arti ON artwork_to_artist (artist_id);
+CREATE INDEX artwork_to_artist_idx_artwork_cd_id_artwork_to_ ON artwork_to_artist (artwork_cd_id);
+
+--
 -- Table: bindtype_test
 --
 CREATE TABLE bindtype_test (




More information about the Bast-commits mailing list