@@ -, +, @@ --- Koha/Objects.pm | 26 ++++++++++++++------------ Koha/Schema/Result/Borrower.pm | 4 ++++ Koha/Schema/Result/Branch.pm | 5 +++++ 3 files changed, 23 insertions(+), 12 deletions(-) --- a/Koha/Objects.pm +++ a/Koha/Objects.pm @@ -142,19 +142,22 @@ Searches the specified relationship, optionally specifying a condition and attri sub search_related { my ( $self, $rel_name, @params ) = @_; + return if !$rel_name; if (wantarray) { my @dbic_rows = $self->_resultset()->search_related($rel_name, @params); - my $object_class = get_object_class( $dbic_rows[0]->result_class )->[1]; + return if !@dbic_rows; + my $object_class = _get_objects_class( $dbic_rows[0]->result_class ); eval "require $object_class"; - return $object_class->_wrap(@dbic_rows); + return _wrap( $object_class, @dbic_rows ); } else { my $rs = $self->_resultset()->search_related($rel_name, @params); - my $object_class = get_object_class( $rs->result_class )->[1]; + return if !$rs; + my $object_class = _get_objects_class( $rs->result_class ); eval "require $object_class"; - return $object_class->_new_from_dbic($rs); + return _new_from_dbic( $object_class, $rs ); } } @@ -295,16 +298,15 @@ sub _resultset { } } -sub get_object_class { +sub _get_objects_class { my ( $type ) = @_; return unless $type; - $type =~ s|^Koha::Schema::Result::||; - my $mappings = { - Branch => [ qw( Koha::Library Koha::Libraries ) ], - Borrower => [ qw( Koha::Patron Koha::Patrons ) ], - OldIssue => [ qw( Koha::OldIssue Koha::OldIssues ) ], - }; - return $mappings->{$type}; + + if( $type->can('koha_objects_class') ) { + return $type->koha_objects_class; + } + $type =~ s|Schema::Result::||; + return "${type}s"; } =head3 columns --- a/Koha/Schema/Result/Borrower.pm +++ a/Koha/Schema/Result/Borrower.pm @@ -1253,4 +1253,8 @@ __PACKAGE__->belongs_to( { borrowernumber => "guarantorid" }, ); +sub koha_objects_class { + 'Koha::Patrons'; +} + 1; --- a/Koha/Schema/Result/Branch.pm +++ a/Koha/Schema/Result/Branch.pm @@ -533,4 +533,9 @@ __PACKAGE__->many_to_many("categorycodes", "branchrelations", "categorycode"); # You can replace this text with custom code or comments, and it will be preserved on regeneration + +sub koha_objects_class { + 'Koha::Libraries'; +} + 1; --