[Bast-commits] r4640 - DBIx-Class-Tree-NestedSet/lib/DBIx/Class/Tree

rafl at dev.catalyst.perl.org rafl at dev.catalyst.perl.org
Fri Jul 25 01:54:41 BST 2008


Author: rafl
Date: 2008-07-25 01:54:40 +0100 (Fri, 25 Jul 2008)
New Revision: 4640

Modified:
   DBIx-Class-Tree-NestedSet/lib/DBIx/Class/Tree/NestedSet.pm
Log:
Wrap create_related in a transaction.

Modified: DBIx-Class-Tree-NestedSet/lib/DBIx/Class/Tree/NestedSet.pm
===================================================================
--- DBIx-Class-Tree-NestedSet/lib/DBIx/Class/Tree/NestedSet.pm	2008-07-25 00:49:37 UTC (rev 4639)
+++ DBIx-Class-Tree-NestedSet/lib/DBIx/Class/Tree/NestedSet.pm	2008-07-25 00:54:40 UTC (rev 4640)
@@ -99,12 +99,18 @@
 sub create_related {
     my ($self, $rel, $col_data) = @_;
 
+    if ($rel ne $self->tree_columns->{children_rel}) {
+        return $self->next::method($rel => $col_data);
+    }
+
     my %col_data = %{ $col_data };
-    if ($rel eq $self->tree_columns->{children_rel}) {
-        my ($root, $left, $right) = map {
-            $self->tree_columns->{"${_}_column"}
-        } qw/root left right/;
+    my ($root, $left, $right) = map {
+        $self->tree_columns->{"${_}_column"}
+    } qw/root left right/;
 
+    my $row;
+    my $get_row = $self->next::can;
+    $self->result_source->schema->txn_do(sub {
         $self->discard_changes;
         my $p_rgt = $self->$right;
 
@@ -114,9 +120,10 @@
         });
 
         @col_data{$root, $left, $right} = ($self->$root, $p_rgt, $p_rgt + 1);
-    }
+        $row = $get_row->($self, $rel => \%col_data);
+    });
 
-    return $self->next::method($rel => \%col_data);
+    return $row;
 }
 
 sub search_related {




More information about the Bast-commits mailing list