[Bast-commits] r3829 - in DBIx-Class/0.08/trunk: . lib/DBIx/Class t t/lib/DBICTest/Schema

captainL at dev.catalyst.perl.org captainL at dev.catalyst.perl.org
Mon Oct 22 20:45:47 GMT 2007


Author: captainL
Date: 2007-10-22 20:45:46 +0100 (Mon, 22 Oct 2007)
New Revision: 3829

Modified:
   DBIx-Class/0.08/trunk/Changes
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Row.pm
   DBIx-Class/0.08/trunk/t/96multi_create.t
   DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Artist.pm
Log:
fixed problem with duplicate related objects for Row::new/insert

Modified: DBIx-Class/0.08/trunk/Changes
===================================================================
--- DBIx-Class/0.08/trunk/Changes	2007-10-21 22:17:35 UTC (rev 3828)
+++ DBIx-Class/0.08/trunk/Changes	2007-10-22 19:45:46 UTC (rev 3829)
@@ -1,5 +1,5 @@
 Revision history for DBIx::Class
-
+        - Row::insert will now not fall over if passed duplicate related objects
         - When adding relationships, it will throw an exception if you get the
           foreign and self parts the wrong way round in the condition
         - ResultSetColumn::func() now returns all results if called in list

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Row.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Row.pm	2007-10-21 22:17:35 UTC (rev 3828)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Row.pm	2007-10-22 19:45:46 UTC (rev 3829)
@@ -243,7 +243,7 @@
         my $reverse = $source->reverse_relationship_info($relname);
         foreach my $obj (@cands) {
           $obj->set_from_related($_, $self) for keys %$reverse;
-          $obj->insert() if(!$obj->in_storage);
+          $obj->insert() unless ($obj->in_storage || $obj->result_source->resultset->search({$obj->get_columns})->count);
         }
       }
     }

Modified: DBIx-Class/0.08/trunk/t/96multi_create.t
===================================================================
--- DBIx-Class/0.08/trunk/t/96multi_create.t	2007-10-21 22:17:35 UTC (rev 3828)
+++ DBIx-Class/0.08/trunk/t/96multi_create.t	2007-10-22 19:45:46 UTC (rev 3829)
@@ -51,7 +51,24 @@
 
 is($newartist2->name, 'Fred 3', 'Created new artist with cds via find_or_create');
 
+my $artist2 = $schema->resultset('Artist')->create({ artistid => 1000,
+                                                    name => 'Fred 3',
+                                                     cds => [
+                                                             { artist => 1000,
+                                                               title => 'Music to code by',
+                                                               year => 2007,
+                                                             },
+                                                             ],
+                                                    cds_unordered => [
+                                                             { artist => 1000,
+                                                               title => 'Music to code by',
+                                                               year => 2007,
+                                                             },
+                                                             ]
+                                                     });
 
+is($artist2->in_storage, 1, 'artist with duplicate rels inserted okay');
+
 CREATE_RELATED1 :{
 
 	my $artist = $schema->resultset('Artist')->first;

Modified: DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Artist.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Artist.pm	2007-10-21 22:17:35 UTC (rev 3828)
+++ DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Artist.pm	2007-10-22 19:45:46 UTC (rev 3829)
@@ -31,6 +31,9 @@
     cds => 'DBICTest::Schema::CD', undef,
     { order_by => 'year' },
 );
+__PACKAGE__->has_many(
+    cds_unordered => 'DBICTest::Schema::CD'
+);
 
 __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' );
 __PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' );




More information about the Bast-commits mailing list