Skip to content

Commit d6e6414

Browse files
committed
Improved to_json method for Relation
1 parent 0f5915a commit d6e6414

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 6.0.3 (unreleased)
2+
3+
- Improved `to_json` method for `Relation`
4+
15
## 6.0.2 (2025-10-24)
26

37
- Fixed `as_json` method for `HashWrapper`

lib/searchkick/relation.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,10 @@ def respond_to_missing?(...)
644644
Results.new(nil, nil, nil).respond_to?(...) || super
645645
end
646646

647+
def to_json(...)
648+
private_execute.to_a.to_json(...)
649+
end
650+
647651
def to_yaml
648652
private_execute.to_a.to_yaml
649653
end

test/load_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_default
1818
assert_equal "Product A", product.attributes["name"]
1919
assert_equal "Product A", product.as_json["name"]
2020
assert_equal "Product A", JSON.parse(product.to_json)["name"]
21-
assert_equal "Product A", JSON.parse(Product.search("product").to_a.to_json).first["name"]
21+
assert_equal "Product A", JSON.parse(Product.search("product").to_json).first["name"]
2222
end
2323

2424
def test_false
@@ -34,7 +34,7 @@ def test_false
3434
assert_equal "Product A", product.to_h["name"]
3535
assert_equal "Product A", product.as_json["name"]
3636
assert_equal "Product A", JSON.parse(product.to_json)["name"]
37-
assert_equal "Product A", JSON.parse(Product.search("product", load: false).to_a.to_json).first["name"]
37+
assert_equal "Product A", JSON.parse(Product.search("product", load: false).to_json).first["name"]
3838
end
3939

4040
def test_false_methods

0 commit comments

Comments
 (0)