projects
/
kivitendo-erp.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f3345ac
)
linked_records(): Mehrere Model-Namen bei 'from'-/'to'-Parametern
author
Moritz Bunkus
<m.bunkus@linet-services.de>
Wed, 12 Jan 2011 15:01:45 +0000
(16:01 +0100)
committer
Moritz Bunkus
<m.bunkus@linet-services.de>
Wed, 12 Jan 2011 15:15:33 +0000
(16:15 +0100)
SL/DB/Helper/LinkedRecords.pm
patch
|
blob
|
history
diff --git
a/SL/DB/Helper/LinkedRecords.pm
b/SL/DB/Helper/LinkedRecords.pm
index
a1183d7
..
efc44ba
100644
(file)
--- 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}) {
"${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 ]);
}
my $links = SL::DB::Manager::RecordLink->get_all(query => [ and => \@query ]);
@@
-82,9
+83,13
@@
to C<$self> (for C<direction> = C<to>) or that are linked from
C<$self> (for C<direction> = C<from>).
The optional parameter C<from> or C<to> (same as C<direction>)
C<$self> (for C<direction> = C<from>).
The optional parameter C<from> or C<to> (same as C<direction>)
-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');
my $invoices = $order->linked_records(direction => 'to',
to => 'SL::DB::Invoice');