A bunch of tweaks inspired by comments from Dave Howorth.
[dbsrgits/DBIx-Class-Tree.git] / lib / DBIx / Class / Tree / AdjacencyList / Ordered.pm
index 2085f29..57ea891 100644 (file)
@@ -6,8 +6,8 @@ use base qw( DBIx::Class );
 use Carp qw( croak );
 
 __PACKAGE__->load_components(qw(
-    Tree::AdjacencyList
     Ordered
+    Tree::AdjacencyList
 ));
 
 =head1 NAME
@@ -26,7 +26,7 @@ Create a table for your tree data.
   );
 
 In your Schema or DB class add Tree::AdjacencyList::Ordered 
-to the top of the component list.
+to the front of the component list.
 
   __PACKAGE__->load_components(qw( Tree::AdjacencyList::Ordered ... ));
 
@@ -73,16 +73,14 @@ position column.
 
 sub parent_column {
     my $class = shift;
+    my $position_col = $class->position_column() || croak('You must call position_column() before calling parent_column()');
     if (@_) {
-        my $parent_col = shift;
-        my $primary_col = ($class->primary_columns())[0];
-        my $position_col = $class->position_column() || croak('You must call position_column() before calling parent_column()');
-        $class->belongs_to( '_parent' => $class => { "foreign.$primary_col" => "self.$parent_col" } );
-        $class->has_many( 'children' => $class => { "foreign.$parent_col" => "self.$primary_col" }, { order_by=>$position_col } );
-        $class->_parent_column( $parent_col );
+        $class->grouping_column( @_ );
+        $class->next::method( @_ );
+        $class->relationship_info('children')->{attrs}->{order_by} = $position_col;
         return 1;
     }
-    return $class->_parent_column();
+    return $class->grouping_column;
 }
 
 =head2 parent
@@ -190,41 +188,30 @@ sub attach_after {
     $sibling->move_to( $self->get_column($self->position_column()) + 1 );
 }
 
-=head1 PRIVATE METHODS
-
-These methods are used internally.  You should never have the 
-need to use them.
-
-=head2 grouping_column
-
-Postional's grouping_column method does not, and should not, be 
-defined when using this module.  This method just throws out an 
-error if you try to use it.
-
-=cut
-
-sub grouping_column {
-    croak('Use parent_column() instead of grouping_column()');
-}
+1;
+__END__
 
-=head2 _grouping_clause
+=head1 INHERITED METHODS
 
-This method is provided as an override of the method in 
-L<DBIx::Class::Ordered>.  This method is what provides the 
-glue between AdjacencyList and Ordered.
+This module inherits all methods from L<DBIx::Class::Ordered>.
 
-=cut
+  siblings
+  first_sibling
+  last_sibling
+  previous_sibling
+  next_sibling
+  move_previous
+  move_next
+  move_first
+  move_last
+  move_to
+  insert
+  delete
 
-sub _grouping_clause {
-    my( $self ) = @_;
-    my $col = $self->_parent_column();
-    return (
-        $col => $self->get_column( $col )
-    );
-}
+And L<DBIx::Class::Tree::AdjacencyList>.
 
-1;
-__END__
+  attach_child
+  attach_sibling
 
 =head1 AUTHOR