From: Moritz Bunkus Date: Wed, 12 Jan 2011 15:01:45 +0000 (+0100) Subject: linked_records(): Mehrere Model-Namen bei 'from'-/'to'-Parametern X-Git-Tag: release-2.6.3~61^2~7^2~1^2~2^2~93 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=ea20c6e350ed5aea8dd57c48b798e8588186ea61;p=kivitendo-erp.git linked_records(): Mehrere Model-Namen bei 'from'-/'to'-Parametern --- diff --git a/SL/DB/Helper/LinkedRecords.pm b/SL/DB/Helper/LinkedRecords.pm index a1183d75f..efc44ba3b 100644 --- a/SL/DB/Helper/LinkedRecords.pm +++ b/SL/DB/Helper/LinkedRecords.pm @@ -22,8 +22,9 @@ sub linked_records { "${myself}_id" => $self->id ); if ($params{$wanted}) { - my $wanted_table = SL::DB::Helpers::Mappings::get_table_for_package($params{$wanted}) || croak("Invalid parameter `${wanted}'"); - push @query, ("${wanted}_table" => $wanted_table); + my $wanted_classes = ref($params{$wanted}) eq 'ARRAY' ? $params{$wanted} : [ $params{$wanted} ]; + my $wanted_tables = [ map { SL::DB::Helpers::Mappings::get_table_for_package($_) || croak("Invalid parameter `${wanted}'") } @{ $wanted_classes } ]; + push @query, ("${wanted}_table" => $wanted_tables); } my $links = SL::DB::Manager::RecordLink->get_all(query => [ and => \@query ]); @@ -82,9 +83,13 @@ to C<$self> (for C = C) or that are linked from C<$self> (for C = C). The optional parameter C or C (same as C) -contains the package name of a Rose model for table limitation. If you -only need invoices created from an order C<$order> then the call could -look like this: +contains the package names of Rose models for table limitation. It can +be a single model name as a single scalar or multiple model names in +an array reference in which case all links matching any of the model +names will be returned. + +If you only need invoices created from an order C<$order> then the +call could look like this: my $invoices = $order->linked_records(direction => 'to', to => 'SL::DB::Invoice');