Commit e05728dcdc79cb767fcd6f49664e5696f334353d

Authored by Andrew Kane
1 parent 8a0303c5
Exists in master

Fixed Relation loaded error for non-mutating methods on relation - #1395

CHANGELOG.md
... ... @@ -3,6 +3,7 @@
3 3 - Added `model` method to `Searchkick::Relation`
4 4 - Fixed deprecation warning with `redis` gem
5 5 - Fixed `respond_to?` method on relation loading relation
  6 +- Fixed `Relation loaded` error for non-mutating methods on relation
6 7  
7 8 ## 5.0.4 (2022-06-16)
8 9  
... ...
lib/searchkick/relation.rb
... ... @@ -233,5 +233,10 @@ module Searchkick
233 233 def ensure_permitted(obj)
234 234 obj.to_h
235 235 end
  236 +
  237 + def initialize_copy(other)
  238 + super
  239 + @execute = nil
  240 + end
236 241 end
237 242 end
... ...
test/relation_test.rb
... ... @@ -7,6 +7,9 @@ class RelationTest < Minitest::Test
7 7 refute products.loaded?
8 8 assert_equal 0, products.count
9 9 assert products.loaded?
  10 + refute products.clone.loaded?
  11 + refute products.dup.loaded?
  12 + refute products.limit(2).loaded?
10 13 error = assert_raises(Searchkick::Error) do
11 14 products.limit!(2)
12 15 end
... ...