From ef437356e38e576a3db11fa03d3a0a39a4689a7a Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 10 Mar 2023 16:14:50 +0000 Subject: [PATCH] Bug 33493: Add a filter relationship for branchtransfers Prefetching is useful, but we don't want to fetch all the inactive transfers for an item. This patch adds a filtered relationship and updates get_transfer(s) to use this To test: prove -v t/db_dependent/Koha/Item.t Signed-off-by: David Nind --- Koha/Item.pm | 11 +++++------ Koha/Schema/Result/Item.pm | 10 ++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index ea2677a01f..d38265903f 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -565,7 +565,9 @@ we still expect the item to end up at a final location eventually. sub get_transfer { my ($self) = @_; - return $self->get_transfers->search( {}, { rows => 1 } )->next; + my $transfer = $self->_result->branchtransfer; + + return Koha::Item::Transfers->_new_from_dbic($transfer)->next; } =head3 get_transfers @@ -588,12 +590,9 @@ we still expect the item to end up at a final location eventually. sub get_transfers { my ($self) = @_; - my $transfer_rs = $self->_result->branchtransfers; + my $transfer_rs = $self->_result->branchtransfer; - return Koha::Item::Transfers - ->_new_from_dbic($transfer_rs) - ->filter_by_current - ->search( {}, { order_by => [ { -desc => 'datesent' }, { -asc => 'daterequested' } ], } ); + return Koha::Item::Transfers->_new_from_dbic($transfer_rs); } =head3 last_returned_by diff --git a/Koha/Schema/Result/Item.pm b/Koha/Schema/Result/Item.pm index 308a63f804..72112d27d3 100644 --- a/Koha/Schema/Result/Item.pm +++ b/Koha/Schema/Result/Item.pm @@ -972,6 +972,16 @@ __PACKAGE__->many_to_many( "ordernumber", ); +__PACKAGE__->has_many( + "branchtransfer", + "Koha::Schema::Result::Branchtransfer", + { 'foreign.itemnumber' => 'self.itemnumber' }, + { + where => { datearrived => undef, datecancelled => undef }, + order_by => [ { -desc => 'datesent' }, { -asc => 'daterequested' } ] + } +); + use C4::Context; sub effective_itemtype { my ( $self ) = @_; -- 2.30.2