]> git.koha-community.org Git - koha.git/commit
Bug 24528: Add *_count support to to_api
authorTomas Cohen Arazi <tomascohen@theke.io>
Tue, 28 Jan 2020 19:24:51 +0000 (16:24 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Fri, 31 Jan 2020 13:50:39 +0000 (13:50 +0000)
commit58356c12bbaf4dc7eb3f7c918b62f91606062761
tree2e857480b48ceef5bcd14dbc4f36445e42782945
parent578b1aa8f754b49eacb47d0f652e174ab049d47b
Bug 24528: Add *_count support to to_api

This patch adds a way to tell to_api an attribute needs to be calculated
as the count on an existing method/relationship result. For example, if
we wanted to include the holds_count attribute for a Koha::Patron
object, we would call it:

    $ patron_json = $patron->to_api({ embed => { holds_count => { is_count => 1 } } });

This way to_api will internally call

    $json->{holds_count} = $self->holds->count;

To test:
1. Apply the tests patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Object.t
=> FAIL: Tests fail!
3. Apply this patch
4. Repeat (2)
=> SUCCESS: Tests pass!
5. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Koha/Object.pm