Bug 24435 - Add Koha::Biblio->items_count
Summary: Add Koha::Biblio->items_count
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Tomás Cohen Arazi
QA Contact: Testopia
URL:
Keywords:
Depends on: 24430
Blocks: 20212 24467
  Show dependency treegraph
 
Reported: 2020-01-16 16:31 UTC by Tomás Cohen Arazi
Modified: 2020-11-30 21:45 UTC (History)
7 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
20.05.00


Attachments
Bug 24435: Unit tests (1.43 KB, patch)
2020-01-16 16:36 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 24435: Add Koha::Biblio->items_count (1.63 KB, patch)
2020-01-16 16:36 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 24435: Unit tests (1.48 KB, patch)
2020-01-17 10:31 UTC, David Nind
Details | Diff | Splinter Review
Bug 24435: Add Koha::Biblio->items_count (1.68 KB, patch)
2020-01-17 10:31 UTC, David Nind
Details | Diff | Splinter Review
Bug 24435: Unit tests (1.54 KB, patch)
2020-01-17 20:11 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 24435: Add Koha::Biblio->items_count (1.74 KB, patch)
2020-01-17 20:11 UTC, Nick Clemens
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Tomás Cohen Arazi 2020-01-16 16:31:41 UTC
This simple method can be used in several places. For example for embedding counts on related API objects.
Comment 1 Tomás Cohen Arazi 2020-01-16 16:36:44 UTC
Created attachment 97462 [details] [review]
Bug 24435: Unit tests

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 2 Tomás Cohen Arazi 2020-01-16 16:36:47 UTC
Created attachment 97463 [details] [review]
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>
Comment 3 David Nind 2020-01-17 10:31:13 UTC
Created attachment 97489 [details] [review]
Bug 24435: Unit tests

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: David Nind <david@davidnind.com>
Comment 4 David Nind 2020-01-17 10:31:16 UTC
Created attachment 97490 [details] [review]
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>
Comment 5 Nick Clemens 2020-01-17 20:11:39 UTC
Created attachment 97561 [details] [review]
Bug 24435: Unit tests

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>
Comment 6 Nick Clemens 2020-01-17 20:11:42 UTC
Created attachment 97562 [details] [review]
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>
Comment 7 Martin Renvoize 2020-01-21 11:36:56 UTC
Nice work everyone!

Pushed to master for 20.05
Comment 8 Joy Nelson 2020-02-06 22:29:36 UTC
enhancement not backported to 19.11.x