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 242-257
sub _resultset {
Link Here
|
242 |
} |
245 |
} |
243 |
} |
246 |
} |
244 |
|
247 |
|
245 |
sub get_object_class { |
248 |
sub _get_objects_class { |
246 |
my ( $type ) = @_; |
249 |
my ( $type ) = @_; |
247 |
return unless $type; |
250 |
return unless $type; |
248 |
$type =~ s|^Koha::Schema::Result::||; |
251 |
|
249 |
my $mappings = { |
252 |
if( $type->can('koha_objects_class') ) { |
250 |
Branch => [ qw( Koha::Library Koha::Libraries ) ], |
253 |
return $type->koha_objects_class; |
251 |
Borrower => [ qw( Koha::Patron Koha::Patrons ) ], |
254 |
} |
252 |
OldIssue => [ qw( Koha::OldIssue Koha::OldIssues ) ], |
255 |
$type =~ s|Schema::Result::||; |
253 |
}; |
256 |
return "${type}s"; |
254 |
return $mappings->{$type}; |
|
|
255 |
} |
257 |
} |
256 |
|
258 |
|
257 |
=head3 columns |
259 |
=head3 columns |