From: Moritz Bunkus Date: Thu, 7 Feb 2013 12:21:29 +0000 (+0100) Subject: Pflichtenheft-Item: Löschfunktion rekursiv X-Git-Tag: release-3.2.0beta~467^2~249 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=80547a321cf7337027768e99e68eb0d0adbb370d;p=kivitendo-erp.git Pflichtenheft-Item: Löschfunktion rekursiv --- diff --git a/SL/DB/RequirementSpecItem.pm b/SL/DB/RequirementSpecItem.pm index 19f36a90e..9322c32b7 100644 --- a/SL/DB/RequirementSpecItem.pm +++ b/SL/DB/RequirementSpecItem.pm @@ -4,5 +4,37 @@ use strict; use SL::DB::MetaSetup::RequirementSpecItem; use SL::DB::Manager::RequirementSpecItem; +use SL::DB::Helper::ActsAsList; + +__PACKAGE__->meta->add_relationship( + children => { + type => 'one to many', + class => 'SL::DB::RequirementSpecItem', + column_map => { id => 'parent_id' }, + }, +); + +__PACKAGE__->meta->initialize; + +__PACKAGE__->configure_acts_as_list(group_by => [qw(requirement_spec_id parent_id)]); + +__PACKAGE__->before_delete(\&_before_delete_delete_children); + +sub _before_delete_delete_children { + my ($self) = @_; + + foreach my $child (@{ SL::DB::Manager::RequirementSpecItem->get_all(where => [ parent_id => $self->id ]) }) { + my $result = $child->delete; + return $result if !$result; + } + + 1; +} + +sub sorted_children { + my ($self) = @_; + + return [ sort { $a->position <=> $b->position } @{ $self->children } ]; +} 1;