X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FTree%2FAdjacencyList%2FOrdered.pm;h=1481c0ac5fe51439a075421d3ba3713e672b22e1;hb=4b44af230c1a43dd07aa927faf9a5a0dcd730c3a;hp=2085f292c3823759f0569e2938bf4e6d86277fce;hpb=c11aa53357f070e01ccb36fd0a9d7825a5f32b44;p=dbsrgits%2FDBIx-Class-Tree.git diff --git a/lib/DBIx/Class/Tree/AdjacencyList/Ordered.pm b/lib/DBIx/Class/Tree/AdjacencyList/Ordered.pm index 2085f29..1481c0a 100644 --- a/lib/DBIx/Class/Tree/AdjacencyList/Ordered.pm +++ b/lib/DBIx/Class/Tree/AdjacencyList/Ordered.pm @@ -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,132 @@ sub attach_after { $sibling->move_to( $self->get_column($self->position_column()) + 1 ); } -=head1 PRIVATE METHODS +1; +__END__ -These methods are used internally. You should never have the -need to use them. +=head1 INHERITED METHODS -=head2 grouping_column +=head2 DBIx::Class::Ordered -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. +=over 4 -=cut +=item * -sub grouping_column { - croak('Use parent_column() instead of grouping_column()'); -} +L -=head2 _grouping_clause +=item * -This method is provided as an override of the method in -L. This method is what provides the -glue between AdjacencyList and Ordered. +L -=cut +=item * -sub _grouping_clause { - my( $self ) = @_; - my $col = $self->_parent_column(); - return ( - $col => $self->get_column( $col ) - ); -} +L -1; -__END__ +=item * + +L + +=item * + +L + +=item * + +L + +=item * + +L + +=item * + +L + +=item * + +L + +=item * + +L + +=item * + +L + +=item * + +L + +=back + +=head2 DBIx::Class::Tree::AdjacencyList + +=over 4 + +=item * + +L + +=item * + +L + +=item * + +L + +=item * + +L + +=item * + +L + +=back + +=head2 DBIx::Class + +=over 4 + +=item * + +L + +=item * + +L + +=back + +=head2 DBIx::Class::Componentised + +=over 4 + +=item * + +L + +=item * + +L + +=item * + +L + +=back + +=head2 Class::Data::Accessor + +=over 4 + +=item * + +L + +=back =head1 AUTHOR