X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FTree%2FAdjacencyList.pm;h=a77eeda0f36f9c0a869bfe02fc9d7ca8cb0c0323;hb=f77790db189a9ede148067512fb5b890a316c184;hp=e668a383cb896dfbe786727e4ea07d1a0dca8f58;hpb=bfeda3d7b6a362c438889080e6f2c2c834d1c9f2;p=dbsrgits%2FDBIx-Class-Tree.git diff --git a/lib/DBIx/Class/Tree/AdjacencyList.pm b/lib/DBIx/Class/Tree/AdjacencyList.pm index e668a38..a77eeda 100644 --- a/lib/DBIx/Class/Tree/AdjacencyList.pm +++ b/lib/DBIx/Class/Tree/AdjacencyList.pm @@ -66,7 +66,7 @@ stop you from having multiple root nodes. __PACKAGE__->parent_column('parent_id'); Declares the name of the column that contains the self-referential -ID which defines the parent row. This will create a has_many (children) +ID which defines the parent row. This will create a has_many (children) and belongs_to (parent) relationship. This method also sets up an additional has_many relationship called @@ -309,10 +309,7 @@ Returns 1 if the object has no children, and 0 otherwise. sub is_leaf { my( $self ) = @_; - my $has_child = $self->result_source->resultset->search( - { $self->_parent_column => $self->id() }, - { limit => 1 } - )->count(); + my $has_child = $self->children_rs->count(); return $has_child ? 0 : 1; } @@ -365,6 +362,30 @@ sub set_primary_key { 1; __END__ +=head1 CAVEATS + +=head2 Generated schemas + +If you are using L methods either directly +or via L or L, you +will need the following L hook to remove the constraint +from C, otherwise you will not be able to user 0 (zero) as +a value. + + sub sqlt_deploy_hook { + my ($self, $sqlt_table) = @_; + + foreach my $constraint ($sqlt_table->get_constraints) { + if ($constraint->field_names->[0] eq $self->parent_column) { + $sqlt_table->drop_constraint($constraint->name); + last; + } + } + } + +ALso see L for other examples. + =head1 INHERITED METHODS =head2 DBIx::Class