Bug 34360: Get distinct biblionumber
authorNick Clemens <nick@bywatersolutions.com>
Thu, 11 Jan 2024 11:53:42 +0000 (11:53 +0000)
committerKatrin Fischer <katrin.fischer@bsz-bw.de>
Fri, 10 May 2024 12:11:42 +0000 (14:11 +0200)
commitb5388933b64b78ce22b058dd1e5b96e1c0ec78a0
treef58815cb2818598af4fcab1c7131d039a53b3b6b
parent5c43883a7c1241e4e0cd08ff8c6fa62b55899dd9
Bug 34360: Get distinct biblionumber

This fixes the problem noted in the bug:
[WARN] DBIx::Class::ResultSetColumn::new(): Attempting to retrieve non-unique column 'biblionumber' on a resultset containing one-to-many joins will return duplicate results. at /usr/share/koha/Koha/Objects.pm line 421

We are taking a list of items, assuming the scenario is that these are from a single biblio and possibly some host_items, then searching and ordering conditionally on whether the biblio is a serial.

Current code gets the first biblio from the list - this patch adds a 'DISTINCT' to the results ebfore fetching the column

To test:
1 - Find a biblio in the staff interface
2 - Transfer one of the items a few times
3 - Recreate the issue on the command line:
    export DBIC_TRACE=1
    perl -e 'use Koha::Items; my $items = Koha::Items->search({biblionumber=>9})->search_ordered(undef,{ prefetch => ['issue','current_branchtransfers'] }); $items->next'
4 - Note warning:
    DBIx::Class::ResultSetColumn::new(): Attempting to retrieve non-unique column 'biblionumber' on a resultset containing one-to-many joins will return duplicate results. at /kohadevbox/koha/Koha/Objects.pm line 426
5 - Apply patch
6 - Repeat 3
7 - Error is gone

Signed-off-by: baptiste <baptiste.bayche@inlibro.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Koha/Items.pm