diff --git a/Koha/REST/Plugin/Query.pm b/Koha/REST/Plugin/Query.pm index 769fd0b614..80bdf26216 100644 --- a/Koha/REST/Plugin/Query.pm +++ b/Koha/REST/Plugin/Query.pm @@ -263,7 +263,13 @@ sub _parse_embed { $result->{$curr} = { children => _parse_embed( $next ) }; } else { - $result->{$curr} = {}; + if ( $curr =~ m/^(?.*)\+count/ ) { + my $key = $+{relation} . "_count"; + $result->{$key} = { is_count => 1 }; + } + else { + $result->{$curr} = {}; + } } return $result; diff --git a/t/Koha/REST/Plugin/Query.t b/t/Koha/REST/Plugin/Query.t index 44fc48b8be..a10289ac5b 100644 --- a/t/Koha/REST/Plugin/Query.t +++ b/t/Koha/REST/Plugin/Query.t @@ -140,7 +140,8 @@ get '/stash_embed' => sub { 'x-koha-embed' => [ 'checkouts', 'checkouts.item', - 'library' + 'library', + 'holds+count' ] } } @@ -304,7 +305,7 @@ subtest '_build_query_params_from_api' => sub { subtest 'stash_embed() tests' => sub { - plan tests => 12; + plan tests => 15; my $t = Test::Mojo->new; @@ -316,6 +317,10 @@ subtest 'stash_embed() tests' => sub { ->status_is(200) ->json_is( { checkouts => { children => { item => {} } }, library => {} } ); + $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'holds+count' } ) + ->status_is(200) + ->json_is( { holds_count => { is_count => 1 } } ); + $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item,patron' } ) ->status_is(400) ->json_is(