Pflichtenhefte vordef Textblöcke: Verwaltung Flags »benutzbar für…«
[kivitendo-erp.git] / SL / DB / Helper / LinkedRecords.pm
index b75597a..182f3bd 100644 (file)
@@ -148,14 +148,20 @@ sub _linked_records_implementation {
       ORDER BY ${wanted}_table, ${wanted}_id, depth ASC;
 
     my $links     = selectall_hashref_query($::form, $::form->get_standard_dbh, $query, $self->id, $self->meta->table);
+
+    return [] unless @$links;
+
     my $link_objs = SL::DB::Manager::RecordLink->get_all(query => [ id => [ map { $_->{id} } @$links ] ]);
     my @objects = map { $get_objects->($_) } @$link_objs;
 
     if ($params{save_path}) {
        my %links_by_id = map { $_->{id} => $_ } @$links;
        for (@objects) {
-         $_->{_record_link_path}  = $links_by_id{$_->{_record_link}->id}->{path};
-         $_->{_record_link_depth} = $links_by_id{$_->{_record_link}->id}->{depth};
+         my $link = $links_by_id{$_->{_record_link}->id};
+         my $intermediate_links = SL::DB::Manager::RecordLink->get_all(query => [ id => $link->{path} ]);
+         $_->{_record_link_path}     = $link->{path};
+         $_->{_record_link_obj_path} = [ map { $get_objects->($_) } @$intermediate_links ];
+         $_->{_record_link_depth}    = $link->{depth};
        }
     }