[Bast-commits] r4621 - DBIx-Class-Tree-NestedSet/lib/DBIx/Class/Tree
rafl at dev.catalyst.perl.org
rafl at dev.catalyst.perl.org
Fri Jul 25 01:42:59 BST 2008
Author: rafl
Date: 2008-07-25 01:42:59 +0100 (Fri, 25 Jul 2008)
New Revision: 4621
Modified:
DBIx-Class-Tree-NestedSet/lib/DBIx/Class/Tree/NestedSet.pm
Log:
Manage the root, left and right columns.
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:42:52 UTC (rev 4620)
+++ DBIx-Class-Tree-NestedSet/lib/DBIx/Class/Tree/NestedSet.pm 2008-07-25 00:42:59 UTC (rev 4621)
@@ -57,4 +57,46 @@
return $self->parents->first;
}
+sub insert {
+ my $self = shift;
+
+ my ($root, $left, $right) = map {
+ $self->tree_columns->{"${_}_column"}
+ } qw/root left right/;
+
+ if (!$self->$right) {
+ $self->set_columns({
+ $left => 1,
+ $right => 2,
+ });
+ }
+
+ my $row = $self->next::method(@_);
+
+ $row->update({
+ $root => $row->get_column( ($row->result_source->primary_columns)[0] ),
+ }) unless defined $row->$root;
+
+ return $row;
+}
+
+sub create_related {
+ my ($self, $rel, $col_data) = @_;
+
+ my ($root, $left, $right) = map {
+ $self->tree_columns->{"${_}_column"}
+ } qw/root left right/;
+
+ my $p_rgt = $self->$right;
+
+ $self->nodes_rs->update({
+ $left => \"CASE WHEN $left > $p_rgt THEN $left + 2 ELSE $left END",
+ $right => \"CASE WHEN $right >= $p_rgt THEN $right + 2 ELSE $right END",
+ });
+
+ @$col_data{$root, $left, $right} = ($self->$root, $p_rgt, $p_rgt + 1);
+
+ return $self->next::method($rel => $col_data);
+}
+
1;
More information about the Bast-commits
mailing list