I'm using acts_as_tenant gem that injects default scope in my models.
I also use Sunspot for search like so:
Article.search do
with(:organization_id, ActsAsTenant.current_tenant.id)
fulltext params[:search]
end
Article model is scoped so that even if I don't pass current tenant id in search I would only get the right results (just the total would be off).
Now, the problem:
If in some situations I want to ignore default scope coming from acts_as_tenant how can I do it in Solr? This WILL NOT work:
Article.unscoped.search do
with(:organization_id, 999)
fulltext params[:search]
end
it will generate incorrect SQL:
Article Load (34.2ms) SELECT `articles`.* FROM `articles` WHERE `articles`.`id` IN (3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32) AND `articles`.`organization_id` = 1
where organization_id is the current tenant's id
TL;DR: How do I ignore default scope when searching with Sunspot?
I still failed to find a way to ignore the default scope when using sunspot that does not involve forking the gem. However I was able to use
As of today (04 August, 2016) this feature has not yet been released but you can use git repo directly