Commit 4bf7bc8f46caeb0a8f2d72df6da6c15efe1ab756
1 parent
b567a658
Exists in
master
and in
17 other branches
Added pagination warning [skip ci]
Showing
2 changed files
with
10 additions
and
0 deletions
Show diff stats
lib/searchkick/query.rb
... | ... | @@ -63,6 +63,10 @@ module Searchkick |
63 | 63 | # there can be multiple models per index name due to inheritance - see #1259 |
64 | 64 | (@index_mapping[model.searchkick_index.name] ||= []) << model |
65 | 65 | end |
66 | + | |
67 | + if options[:per_page] && @index_mapping.values.flatten.any? { |m| m != m.searchkick_klass } | |
68 | + warn "[searchkick] Passing child models to the models option throws off pagination" | |
69 | + end | |
66 | 70 | end |
67 | 71 | |
68 | 72 | index = | ... | ... |
test/inheritance_test.rb
... | ... | @@ -87,6 +87,12 @@ class InheritanceTest < Minitest::Test |
87 | 87 | store_names ["Bear C"] |
88 | 88 | Animal.reindex |
89 | 89 | assert_equal 2, Searchkick.search("bear", models: [Cat, Product]).size |
90 | + | |
91 | + # pagination will be off with this approach | |
92 | + # ideal case is add where conditions (index a, type a OR index b) | |
93 | + # however, we don't know the exact index name, and aliases don't work for filters | |
94 | + # show warning for now | |
95 | + assert_equal 3, Searchkick.search("bear", models: [Cat, Product], per_page: 1).total_pages | |
90 | 96 | end |
91 | 97 | |
92 | 98 | # TODO move somewhere better | ... | ... |