X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=Koha%2FObjects.pm;h=73d361708884948ee2d7d09678745f3415a42fb0;hb=b8df96082ec84097aac24e2128e6b8d1a34c463e;hp=3f2f64b4b435518f00022551ee73fa7a5da8fe7b;hpb=3d110a3c72432249613bc38333d4c0260a4356c4;p=koha-ffzg.git diff --git a/Koha/Objects.pm b/Koha/Objects.pm index 3f2f64b4b4..73d3617088 100644 --- a/Koha/Objects.pm +++ b/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 ); } } @@ -242,16 +245,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