@@ -, +, @@ $ kshell k$ prove t/db_dependent/Koha/Biblio.t --- Koha/Biblio.pm | 10 +++++++++- t/db_dependent/Koha/Biblio.t | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) --- a/Koha/Biblio.pm +++ a/Koha/Biblio.pm @@ -737,8 +737,16 @@ on the API. sub to_api { my ($self, $args) = @_; + my @embeds = keys %{ $args->{embed} }; + my $remaining_embeds = {}; + + foreach my $embed (@embeds) { + $remaining_embeds = delete $args->{embed}->{$embed} + unless $self->can($embed); + } + my $response = $self->SUPER::to_api( $args ); - my $biblioitem = $self->biblioitem->to_api( $args ); + my $biblioitem = $self->biblioitem->to_api({ embed => $remaining_embeds }); return { %$response, %$biblioitem }; } --- a/t/db_dependent/Koha/Biblio.t +++ a/t/db_dependent/Koha/Biblio.t @@ -440,14 +440,19 @@ subtest 'to_api() tests' => sub { $schema->storage->txn_begin; my $biblio = $builder->build_sample_biblio(); + my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); + my $biblioitem_api = $biblio->biblioitem->to_api; my $biblio_api = $biblio->to_api; - plan tests => scalar keys %{ $biblioitem_api }; + plan tests => (scalar keys %{ $biblioitem_api }) + 1; foreach my $key ( keys %{ $biblioitem_api } ) { is( $biblio_api->{$key}, $biblioitem_api->{$key}, "$key is added to the biblio object" ); } + $biblio_api = $biblio->to_api({ embed => { items => {} } }); + is_deeply( $biblio_api->{items}, [ $item->to_api ], 'Item correctly embedded' ); + $schema->storage->txn_rollback; }; --