Bug 24435: Add Koha::Biblio->items_count
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 16 Jan 2020 16:32:25 +0000 (13:32 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 21 Jan 2020 11:25:14 +0000 (11:25 +0000)
commit637e82729b76e406517c140f69e9071cc48ca199
tree2c897ffe52003965bb54bc5367723ed4f078cac5
parent293f9565d05293aee53a999992e75487e61300bc
Bug 24435: Add Koha::Biblio->items_count

This patch introduces a handy shortcut to get the items count for a
biblio. So instead of calling:

  $count = $biblio->items->count;
you can call:
  $count = $biblio->items_count;

The use case for this, is when we want to embed information on objects
to be sent as API responses. In that case, calling ->items->count needs
to be done manually on the controller script, with interesting added
complexity. With this kind of method, we can just require it to be
embedded automagically by calling the following on the API:

   $biblio->to_api({ embed => { items_count => {} } });

If there are several nested layers of objects, doing manually can get
really tricky and error prone.

To test:
1. Apply this patches
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Biblio.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Koha/Biblio.pm