使用STI时,使用Thinking Sphinx范围获取"未定义的方法"

Cod*_*eef 6 thinking-sphinx ruby-on-rails-3

我正在使用Thinking Sphinx 2.0.13和Rails 3.2.9.

鉴于我有和STI类看起来像这样:

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
Run Code Online (Sandbox Code Playgroud)

如果我尝试在User或Admin类上使用单个作用域,则一切正常.我也可以按照预期使用User模型将范围链接在一起.问题是,如果我在Admin模型上链接范围,我得到:

> 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>
Run Code Online (Sandbox Code Playgroud)

遇到第一个作用域时,它似乎正在运行查询.是否有一些明显我缺失的东西,或者这看起来像TS的问题?

hca*_*ver 0

以下是您之前遇到过的一些问题,sphinx_scopes这些问题可能就是这里的问题。

  • 人们发现他们的sphinx_scopes. 您的范围by_account是最佳选择,因此请尝试重命名它。我可以想象这种情况在派生类中会出现混乱,但在基类中不会出现这种情况。
  • 过去的范围问题可以通过重新排序调用来解决,因此请尝试Admin.without_deleted.by_account(1). 我知道这不是解决办法。
  • 我还预测这account_id是一个主键(即每个最多一个UserAccount。如果是这样,这可以解释为什么Rails选择过早地获取它。