From 3488e6ea4540a9c071b5055a8ee6bb32f6dbf8f9 Mon Sep 17 00:00:00 2001
From: Tomas Cohen Arazi <tomascohen@theke.io>
Date: Tue, 17 Aug 2021 11:37:28 -0300
Subject: [PATCH] Bug 28871: Make Koha::Objects->empty work on list context

This patch makes Koha::Objects->empty work on list context, by making it
return the $self->search call.

To test:
1. Apply the regression test patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Objects.t
=> FAIL: Tests fail!
3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass!
5. Sign off :-D

Note: this patch has the side effect of making Koha::Objects->new->empty
to perform a search on the DB. I'm not sure how to solve this because
the cache needs to be set after the resultset is generated. It feels
like a cleaner approach (i.e. not using the set_cache method).
---
 Koha/Objects.pm | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/Koha/Objects.pm b/Koha/Objects.pm
index 3ee0a55742..1cd2ec0907 100644
--- a/Koha/Objects.pm
+++ b/Koha/Objects.pm
@@ -380,10 +380,9 @@ sub empty {
         class  => $self
     ) unless ref $self;
 
-    $self = $self->search(\'0 = 1');
     $self->_resultset()->set_cache([]);
 
-    return $self;
+    return $self->search(\'0 = 1');
 }
 
 =head3 Koha::Objects->reset();
-- 
2.30.2