Revision 80547a32
Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt
SL/DB/RequirementSpecItem.pm | ||
---|---|---|
4 | 4 |
|
5 | 5 |
use SL::DB::MetaSetup::RequirementSpecItem; |
6 | 6 |
use SL::DB::Manager::RequirementSpecItem; |
7 |
use SL::DB::Helper::ActsAsList; |
|
8 |
|
|
9 |
__PACKAGE__->meta->add_relationship( |
|
10 |
children => { |
|
11 |
type => 'one to many', |
|
12 |
class => 'SL::DB::RequirementSpecItem', |
|
13 |
column_map => { id => 'parent_id' }, |
|
14 |
}, |
|
15 |
); |
|
16 |
|
|
17 |
__PACKAGE__->meta->initialize; |
|
18 |
|
|
19 |
__PACKAGE__->configure_acts_as_list(group_by => [qw(requirement_spec_id parent_id)]); |
|
20 |
|
|
21 |
__PACKAGE__->before_delete(\&_before_delete_delete_children); |
|
22 |
|
|
23 |
sub _before_delete_delete_children { |
|
24 |
my ($self) = @_; |
|
25 |
|
|
26 |
foreach my $child (@{ SL::DB::Manager::RequirementSpecItem->get_all(where => [ parent_id => $self->id ]) }) { |
|
27 |
my $result = $child->delete; |
|
28 |
return $result if !$result; |
|
29 |
} |
|
30 |
|
|
31 |
1; |
|
32 |
} |
|
33 |
|
|
34 |
sub sorted_children { |
|
35 |
my ($self) = @_; |
|
36 |
|
|
37 |
return [ sort { $a->position <=> $b->position } @{ $self->children } ]; |
|
38 |
} |
|
7 | 39 |
|
8 | 40 |
1; |
Auch abrufbar als: Unified diff
Pflichtenheft-Item: Löschfunktion rekursiv