Commit d7e3310e5f6321f78f25d79e80603c182d5292b9
1 parent
bff30612
Exists in
relation
Better model handling [skip ci]
Showing
1 changed file
with
7 additions
and
1 deletions
Show diff stats
lib/searchkick/relation.rb
@@ -222,11 +222,17 @@ module Searchkick | @@ -222,11 +222,17 @@ module Searchkick | ||
222 | end | 222 | end |
223 | 223 | ||
224 | def models(*args) | 224 | def models(*args) |
225 | + raise ArgumentError, "Use Searchkick.search to search multiple models" if klass | ||
225 | spawn.models!(*args) | 226 | spawn.models!(*args) |
226 | end | 227 | end |
227 | 228 | ||
228 | def models!(*args) | 229 | def models!(*args) |
229 | - options[:models] = Array(options[:models]) + args | 230 | + # make Searchkick.search.models(Product) and Product.search equivalent |
231 | + if !klass && args.size == 1 && !options[:models] | ||
232 | + @klass = args.first | ||
233 | + else | ||
234 | + options[:models] = Array(options[:models]) + args | ||
235 | + end | ||
230 | self | 236 | self |
231 | end | 237 | end |
232 | 238 |