You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I have an application using Rails 6 and Rails-Admin. Upgrading searchkick to 5.x makes all rails_admin pages fail with "search must be called on model, not relation" (because rails_admin always uses a scope). However, even if I exit the scope by calling unscoped, this failure still occurs. I believe that in addition to checking for current_scope.nil?, searchkick should also check for current_scope == {}
To reproduce
Use this code to reproduce when possible:
require"bundler/inline"gemfiledosource"https://rubygems.org"gem"sqlite3",platform: :rubygem"activerecord","~>6.0",require: "active_record"gem"activejob","~>6.0",require: "active_job"gem"searchkick","~>5.1"gem"elasticsearch",">= 7.5","< 7.14"endputs"Searchkick version: #{Searchkick::VERSION}"puts"Server version: #{Searchkick.server_version}"ActiveRecord::Base.establish_connectionadapter: "sqlite3",database: ":memory:"ActiveJob::Base.queue_adapter=:inlineActiveRecord::Schema.definedocreate_table:examplesdo |t|
t.string:namet.string:descriptionendendclassExample < ActiveRecord::Basesearchkickscope:with_name,->(){where("NAME IS NOT NULL")}defself.custom_search(query)unscopeddosearch(query,fields: [:name]).responseendendendExample.reindexExample.create!(name: "Test",description: "Foo")Example.create!(name: "Test 2",description: "Bar")Example.create!(description: "Baz")Example.search_index.refresh# this should workpExample.with_name.custom_search("test")
Additional context
Changing relation? to the following definition make unscoped work:
module Searchkick
def self.relation?(klass)
if klass.respond_to?(:current_scope)
!(klass.current_scope.nil? || klass.send(:scope_attributes) == {})
else
klass.is_a?(Mongoid::Criteria) || !Mongoid::Threaded.current_scope(klass).nil?
end
end
end
The text was updated successfully, but these errors were encountered:
Describe the bug
I have an application using Rails 6 and Rails-Admin. Upgrading searchkick to 5.x makes all rails_admin pages fail with "search must be called on model, not relation" (because rails_admin always uses a scope). However, even if I exit the scope by calling
unscoped
, this failure still occurs. I believe that in addition to checking forcurrent_scope.nil?
, searchkick should also check forcurrent_scope == {}
To reproduce
Use this code to reproduce when possible:
Additional context
Changing
relation?
to the following definition make unscoped work:The text was updated successfully, but these errors were encountered: