From 4bf7bc8f46caeb0a8f2d72df6da6c15efe1ab756 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Fri, 3 May 2019 15:07:00 -0700 Subject: [PATCH] Added pagination warning [skip ci] --- lib/searchkick/query.rb | 4 ++++ test/inheritance_test.rb | 6 ++++++ 2 files changed, 10 insertions(+), 0 deletions(-) diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index 554c68a..0c2fa7e 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -63,6 +63,10 @@ module Searchkick # there can be multiple models per index name due to inheritance - see #1259 (@index_mapping[model.searchkick_index.name] ||= []) << model end + + if options[:per_page] && @index_mapping.values.flatten.any? { |m| m != m.searchkick_klass } + warn "[searchkick] Passing child models to the models option throws off pagination" + end end index = diff --git a/test/inheritance_test.rb b/test/inheritance_test.rb index d5cb917..2b61e23 100644 --- a/test/inheritance_test.rb +++ b/test/inheritance_test.rb @@ -87,6 +87,12 @@ class InheritanceTest < Minitest::Test store_names ["Bear C"] Animal.reindex assert_equal 2, Searchkick.search("bear", models: [Cat, Product]).size + + # pagination will be off with this approach + # ideal case is add where conditions (index a, type a OR index b) + # however, we don't know the exact index name, and aliases don't work for filters + # show warning for now + assert_equal 3, Searchkick.search("bear", models: [Cat, Product], per_page: 1).total_pages end # TODO move somewhere better -- libgit2 0.21.0