Bug 34639: Use coderef for releationship
authorNick Clemens <nick@bywatersolutions.com>
Tue, 29 Aug 2023 12:17:14 +0000 (12:17 +0000)
committerFridolin Somers <fridolin.somers@biblibre.com>
Fri, 8 Sep 2023 19:58:15 +0000 (09:58 -1000)
commitd06eba443cd9d60eddc199f4e5f35e64cce79412
tree29320bfbb05071a1438589ab1715f83c4558ca2b
parent03af78e761843efb25fe077511449adf41149d8f
Bug 34639: Use coderef for releationship

This patch switches from a simple relationship to a custom join as
illustrated in the DBIx::Class docs

Reference:
https://metacpan.org/pod/DBIx::Class::Relationship::Base#Custom-join-conditions

This does not include an order_by, so I am not sure if it is sufficient

To test:
1 - On command line:
    export DBIC_TRACE=1;
2 - Save simple script:
use Modern::Perl;
use Koha::Items;

my $items = Koha::Items->search( {'me.itemnumber'=>27}, {prefetch => 'current_branchtransfers'} );
my $item = $items->next;

warn $item->_result->current_branchtransfers->count();
warn $item->get_transfer();
3 - run it
4 - Note that the query doesn't include conditions on the transfers
5 - Apply patch
6 - Repeat
7 - Note that query is correct

Test in staf client:
1. Add an item to library A
2. Go to Circulation -> Transfer
3. Transfer the item from library A to another library B
4. Set your currently logged in library to library B
5. Check-in the item
6. Observe message "Item received from A"
7. View the bibliographic record of the item (catalogue/detail.pl)
8. Observe item in "In transit from A to B since xx/xx/xxxx Available"
9. Apply patch
10. Restart all
11. Reload details - item no longer in transit

Signed-off-by: Lari Taskula <lari.taskula@hypernova.fi>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 74b205649bbbf59ab512e71dcad8d13046a13670)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Koha/Schema/Result/Item.pm