diff --git a/CHANGELOG.md b/CHANGELOG.md index 4079e918..3709368c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Added `model` method to `Searchkick::Relation` - Fixed deprecation warning with `redis` gem - Fixed `respond_to?` method on relation loading relation +- Fixed `Relation loaded` error for non-mutating methods on relation ## 5.0.4 (2022-06-16) diff --git a/lib/searchkick/relation.rb b/lib/searchkick/relation.rb index adcfc89c..2fec0fcb 100644 --- a/lib/searchkick/relation.rb +++ b/lib/searchkick/relation.rb @@ -233,5 +233,10 @@ def check_loaded def ensure_permitted(obj) obj.to_h end + + def initialize_copy(other) + super + @execute = nil + end end end diff --git a/test/relation_test.rb b/test/relation_test.rb index 7fa5d7bb..f82a5ed4 100644 --- a/test/relation_test.rb +++ b/test/relation_test.rb @@ -7,6 +7,9 @@ def test_loaded refute products.loaded? assert_equal 0, products.count assert products.loaded? + refute products.clone.loaded? + refute products.dup.loaded? + refute products.limit(2).loaded? error = assert_raises(Searchkick::Error) do products.limit!(2) end