1 package SL::DB::RequirementSpecItem;
5 use SL::DB::MetaSetup::RequirementSpecItem;
6 use SL::DB::Manager::RequirementSpecItem;
7 use SL::DB::Helper::ActsAsList;
9 __PACKAGE__->meta->add_relationship(
11 type => 'one to many',
12 class => 'SL::DB::RequirementSpecItem',
13 column_map => { id => 'parent_id' },
16 map_class => 'SL::DB::RequirementSpecDependency',
17 map_from => 'depending_item',
18 map_to => 'depended_item',
19 type => 'many to many',
22 map_class => 'SL::DB::RequirementSpecDependency',
23 map_from => 'depended_item',
24 map_to => 'depending_item',
25 type => 'many to many',
29 __PACKAGE__->meta->initialize;
31 __PACKAGE__->configure_acts_as_list(group_by => [qw(requirement_spec_id parent_id)]);
33 __PACKAGE__->before_delete(\&_before_delete_delete_children);
35 sub _before_delete_delete_children {
38 foreach my $child (@{ SL::DB::Manager::RequirementSpecItem->get_all(where => [ parent_id => $self->id ]) }) {
39 my $result = $child->delete;
40 return $result if !$result;
50 push @errors, t8('The title is missing.') if !$self->parent_id && !$self->title;
58 return [ sort { $a->position <=> $b->position } @{ $self->children } ];
64 $self = $self->parent while $self->parent_id;
72 return 'section' if !$self->parent_id;
73 return $self->parent->parent_id ? 'sub-function-block' : 'function-block';