Revision eb0d6c3a
Von Moritz Bunkus vor fast 14 Jahren hinzugefügt
SL/DB/Helper/LinkedRecords.pm | ||
---|---|---|
1 |
package SL::DB::Helpers::LinkedRecords;
|
|
1 |
package SL::DB::Helper::LinkedRecords; |
|
2 | 2 |
|
3 | 3 |
use strict; |
4 | 4 |
|
... | ... | |
9 | 9 |
use Carp; |
10 | 10 |
use Sort::Naturally; |
11 | 11 |
|
12 |
use SL::DB::Helpers::Mappings;
|
|
12 |
use SL::DB::Helper::Mappings; |
|
13 | 13 |
use SL::DB::RecordLink; |
14 | 14 |
|
15 | 15 |
sub linked_records { |
... | ... | |
47 | 47 |
|
48 | 48 |
my $myself = $wanted eq 'from' ? 'to' : $wanted eq 'to' ? 'from' : croak("Invalid parameter `direction'"); |
49 | 49 |
|
50 |
my $my_table = SL::DB::Helpers::Mappings::get_table_for_package(ref($self));
|
|
50 |
my $my_table = SL::DB::Helper::Mappings::get_table_for_package(ref($self)); |
|
51 | 51 |
|
52 | 52 |
my @query = ( "${myself}_table" => $my_table, |
53 | 53 |
"${myself}_id" => $self->id ); |
54 | 54 |
|
55 | 55 |
if ($params{$wanted}) { |
56 | 56 |
my $wanted_classes = ref($params{$wanted}) eq 'ARRAY' ? $params{$wanted} : [ $params{$wanted} ]; |
57 |
my $wanted_tables = [ map { SL::DB::Helpers::Mappings::get_table_for_package($_) || croak("Invalid parameter `${wanted}'") } @{ $wanted_classes } ];
|
|
57 |
my $wanted_tables = [ map { SL::DB::Helper::Mappings::get_table_for_package($_) || croak("Invalid parameter `${wanted}'") } @{ $wanted_classes } ]; |
|
58 | 58 |
push @query, ("${wanted}_table" => $wanted_tables); |
59 | 59 |
} |
60 | 60 |
|
... | ... | |
67 | 67 |
@query = ref($params{query}) eq 'ARRAY' ? @{ $params{query} } : (); |
68 | 68 |
|
69 | 69 |
foreach my $link (@{ $links }) { |
70 |
my $manager_class = SL::DB::Helpers::Mappings::get_manager_package_for_table($link->$sub_wanted_table);
|
|
71 |
my $object_class = SL::DB::Helpers::Mappings::get_package_for_table($link->$sub_wanted_table);
|
|
70 |
my $manager_class = SL::DB::Helper::Mappings::get_manager_package_for_table($link->$sub_wanted_table); |
|
71 |
my $object_class = SL::DB::Helper::Mappings::get_package_for_table($link->$sub_wanted_table); |
|
72 | 72 |
eval "require " . $object_class . "; 1;"; |
73 | 73 |
push @{ $records }, @{ $manager_class->get_all(query => [ id => $link->$sub_wanted_id, @query ]) }; |
74 | 74 |
} |
... | ... | |
194 | 194 |
|
195 | 195 |
=head1 NAME |
196 | 196 |
|
197 |
SL::DB::Helpers::LinkedRecords - Mixin for retrieving linked records via the table C<record_links>
|
|
197 |
SL::DB::Helper::LinkedRecords - Mixin for retrieving linked records via the table C<record_links> |
|
198 | 198 |
|
199 | 199 |
=head1 FUNCTIONS |
200 | 200 |
|
Auch abrufbar als: Unified diff
ZZZZZumben!