Commit e05728dcdc79cb767fcd6f49664e5696f334353d

Authored by Andrew Kane
1 parent 8a0303c5
Exists in master

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

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