Getting the "undefined method" with Sphinx thinking areas using STI

I am using Thinking Sphinx 2.0.13 with Rails 3.2.9.

Given that I have an STI class that looks like this:

class User < ActiveRecord::Base define_index do has :account_id has :is_deleted end sphinx_scope(:by_account) do |account_id| {:with => {:account_id => account_id}} end sphinx_scope(:without_deleted) do {:with => {:is_deleted => false}} end end class Admin < User end 

If I try to use one scope in the User or Admin class, everything is fine. I can also combine areas using the User model, as expected. The problem is that if I bind the scope to the admin model, I get:

 > Admin.by_account(1).without_deleted NoMethodError: Sphinx Query (2.9ms) Sphinx Found 3 results Admin Load (0.6ms) SELECT `users`.* FROM `users` WHERE `users`.`type` IN ('Admin') AND `users`.`id` IN (7, 8, 9) undefined method `without_deleted' for #<ThinkingSphinx::Search:0x007fd3d95f7a08> 

It seems that the query is being executed as soon as the first area is seen. Is there something obvious that I'm missing, or does it seem like a problem with TS?

+6
source share
1 answer

Here are some problems that people have encountered with sphinx_scopes that may occur here.

  • People have discovered problems with name conflicts in their sphinx_scopes . Your reach by_account is the main candidate for him, so try renaming it. I can imagine situations when this happens in a derived class, but not in a base class.
  • Area issues in the past have been handled by reordering calls, so try Admin.without_deleted.by_account(1) . I don’t know, I know.
  • I also predicted that account_id is the primary key (i.e. no more than one User per Account ). If so, this may explain why Rails chooses to receive prematurely.
0
source

All Articles