Commit 43ad72520f6d9b6ae5c9514f40a1aa638a48f96e
1 parent
a1466b69
Exists in
relation
Added none [skip ci]
Showing
2 changed files
with
14 additions
and
0 deletions
Show diff stats
lib/searchkick/relation.rb
@@ -87,6 +87,15 @@ module Searchkick | @@ -87,6 +87,15 @@ module Searchkick | ||
87 | self | 87 | self |
88 | end | 88 | end |
89 | 89 | ||
90 | + def none | ||
91 | + spawn.none! | ||
92 | + end | ||
93 | + | ||
94 | + def none! | ||
95 | + options[:limit] = 0 # TODO use where? | ||
96 | + self | ||
97 | + end | ||
98 | + | ||
90 | def select(*fields, &block) | 99 | def select(*fields, &block) |
91 | if block_given? | 100 | if block_given? |
92 | # TODO better error message | 101 | # TODO better error message |
test/relation_test.rb
@@ -17,6 +17,11 @@ class RelationTest < Minitest::Test | @@ -17,6 +17,11 @@ class RelationTest < Minitest::Test | ||
17 | assert_search_relation [], Product.search("*").where(name: "Product A").where(name: "Product B") | 17 | assert_search_relation [], Product.search("*").where(name: "Product A").where(name: "Product B") |
18 | end | 18 | end |
19 | 19 | ||
20 | + def test_none | ||
21 | + store_names ["Product A", "Product B"] | ||
22 | + assert_search_relation [], Product.search("*").none | ||
23 | + end | ||
24 | + | ||
20 | def test_parameters | 25 | def test_parameters |
21 | skip unless defined?(ActiveRecord) | 26 | skip unless defined?(ActiveRecord) |
22 | require "action_controller" | 27 | require "action_controller" |