@@ -, +, @@ --- Koha/Objects.pm | 13 +++++++++++++ t/db_dependent/Koha/Objects.t | 13 ++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) --- a/Koha/Objects.pm +++ a/Koha/Objects.pm @@ -130,6 +130,19 @@ sub search { } } +=head3 search_related + + my @objects = Koha::Objects->search_related( $rel_name, $cond?, \%attrs? ); + +Searches the specified relationship, optionally specifying a condition and attributes for matching records. + +=cut + +sub search_related { + my ( $self, @params ) = @_; + return $self->_resultset->search_related( @params ); +} + =head3 Koha::Objects->count(); my @objects = Koha::Objects->count($params); --- a/t/db_dependent/Koha/Objects.t +++ a/t/db_dependent/Koha/Objects.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 4; use Koha::Authority::Types; use Koha::Cities; @@ -51,5 +51,16 @@ subtest 'update' => sub { is( Koha::Cities->search( { city_country => 'UK' } )->count, 0, 'Koha::Objects->update should have updated the 3 rows' ); }; +subtest 'search_related' => sub { + plan tests => 3; + my $builder = t::lib::TestBuilder->new; + my $patron_1 = $builder->build( { source => 'Borrower' } ); + my $patron_2 = $builder->build( { source => 'Borrower' } ); + my $libraries = Koha::Patrons->search( { -or => { borrowernumber => [ $patron_1->{borrowernumber}, $patron_2->{borrowernumber} ] } } )->search_related('branchcode'); + is( $libraries->count, 2, 'Koha::Objects->search_related should work as expected' ); + is( $libraries->next->branchcode, $patron_1->{branchcode}, 'Koha::Objects->search_related should work as expected' ); + is( $libraries->next->branchcode, $patron_2->{branchcode}, 'Koha::Objects->search_related should work as expected' ); +}; + $schema->storage->txn_rollback; 1; --