|
Lines 142-160
Searches the specified relationship, optionally specifying a condition and attri
Link Here
|
| 142 |
sub search_related { |
142 |
sub search_related { |
| 143 |
my ( $self, $rel_name, @params ) = @_; |
143 |
my ( $self, $rel_name, @params ) = @_; |
| 144 |
|
144 |
|
|
|
145 |
return if !$rel_name; |
| 145 |
if (wantarray) { |
146 |
if (wantarray) { |
| 146 |
my @dbic_rows = $self->_resultset()->search_related($rel_name, @params); |
147 |
my @dbic_rows = $self->_resultset()->search_related($rel_name, @params); |
| 147 |
my $object_class = get_object_class( $dbic_rows[0]->result_class )->[1]; |
148 |
return if !@dbic_rows; |
|
|
149 |
my $object_class = _get_objects_class( $dbic_rows[0]->result_class ); |
| 148 |
|
150 |
|
| 149 |
eval "require $object_class"; |
151 |
eval "require $object_class"; |
| 150 |
return $object_class->_wrap(@dbic_rows); |
152 |
return _wrap( $object_class, @dbic_rows ); |
| 151 |
|
153 |
|
| 152 |
} else { |
154 |
} else { |
| 153 |
my $rs = $self->_resultset()->search_related($rel_name, @params); |
155 |
my $rs = $self->_resultset()->search_related($rel_name, @params); |
| 154 |
my $object_class = get_object_class( $rs->result_class )->[1]; |
156 |
return if !$rs; |
|
|
157 |
my $object_class = _get_objects_class( $rs->result_class ); |
| 155 |
|
158 |
|
| 156 |
eval "require $object_class"; |
159 |
eval "require $object_class"; |
| 157 |
return $object_class->_new_from_dbic($rs); |
160 |
return _new_from_dbic( $object_class, $rs ); |
| 158 |
} |
161 |
} |
| 159 |
} |
162 |
} |
| 160 |
|
163 |
|
|
Lines 295-310
sub _resultset {
Link Here
|
| 295 |
} |
298 |
} |
| 296 |
} |
299 |
} |
| 297 |
|
300 |
|
| 298 |
sub get_object_class { |
301 |
sub _get_objects_class { |
| 299 |
my ( $type ) = @_; |
302 |
my ( $type ) = @_; |
| 300 |
return unless $type; |
303 |
return unless $type; |
| 301 |
$type =~ s|^Koha::Schema::Result::||; |
304 |
|
| 302 |
my $mappings = { |
305 |
if( $type->can('koha_objects_class') ) { |
| 303 |
Branch => [ qw( Koha::Library Koha::Libraries ) ], |
306 |
return $type->koha_objects_class; |
| 304 |
Borrower => [ qw( Koha::Patron Koha::Patrons ) ], |
307 |
} |
| 305 |
OldIssue => [ qw( Koha::OldIssue Koha::OldIssues ) ], |
308 |
$type =~ s|Schema::Result::||; |
| 306 |
}; |
309 |
return "${type}s"; |
| 307 |
return $mappings->{$type}; |
|
|
| 308 |
} |
310 |
} |
| 309 |
|
311 |
|
| 310 |
=head3 columns |
312 |
=head3 columns |