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的问题?
以下是您之前遇到过的一些问题,sphinx_scopes
这些问题可能就是这里的问题。
sphinx_scopes
. 您的范围by_account
是最佳选择,因此请尝试重命名它。我可以想象这种情况在派生类中会出现混乱,但在基类中不会出现这种情况。Admin.without_deleted.by_account(1)
. 我知道这不是解决办法。account_id
是一个主键(即每个最多一个User
)Account
。如果是这样,这可以解释为什么Rails
选择过早地获取它。 归档时间: |
|
查看次数: |
518 次 |
最近记录: |