Fix MC double-object creation (important for e.g. IC::FS which otherwise leaves orpha...
Peter Rabbitson [Sun, 30 May 2010 22:27:18 +0000 (22:27 +0000)]
Changes
lib/DBIx/Class/Row.pm

diff --git a/Changes b/Changes
index 43c87a8..0ef7352 100644 (file)
--- a/Changes
+++ b/Changes
@@ -32,7 +32,10 @@ Revision history for DBIx::Class
         - update() on row not in_storage no longer throws an exception
           if there are no dirty columns to update (fixes cascaded update
           annoyances)
-        - Update Schema::Versioned to respect hashref style of connection_info
+        - Update Schema::Versioned to respect hashref style of
+          connection_info
+        - Do not recreate the same related object twice during MultiCreate
+          (solves the problem of orphaned IC::FS files)
 
     * Misc
         - Add a warning to load_namespaces if a class in ResultSet/
index 6678a79..cf4c24c 100644 (file)
@@ -405,18 +405,13 @@ sub insert {
       my $reverse = $source->reverse_relationship_info($relname);
       foreach my $obj (@cands) {
         $obj->set_from_related($_, $self) for keys %$reverse;
-        my $them = { %{$obj->{_relationship_data} || {} }, $obj->get_inflated_columns };
         if ($self->__their_pk_needs_us($relname)) {
           if (exists $self->{_ignore_at_insert}{$relname}) {
             MULTICREATE_DEBUG and warn "MC $self skipping post-insert on $relname";
-          } else {
-            MULTICREATE_DEBUG and warn "MC $self re-creating $relname $obj";
-            my $re = $self->result_source
-                          ->related_source($relname)
-                          ->resultset
-                          ->create($them);
-            %{$obj} = %{$re};
-            MULTICREATE_DEBUG and warn "MC $self new $relname $obj";
+          }
+          else {
+            MULTICREATE_DEBUG and warn "MC $self inserting $relname $obj";
+            $obj->insert;
           }
         } else {
           MULTICREATE_DEBUG and warn "MC $self post-inserting $obj";