6

I'm using Thinking Sphinx 2.0.13 with Rails 3.2.9.

Given I have and 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 attempt to use a single scope on either the User or Admin class, all is fine. I can also chain scopes together using the User model, as expected. The problem is, If I chain scopes on 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 appears to be running the query as soon as the first scope is encountered. Is there something obvious I'm missing, or does this look like an issue with TS?

4

1 回答 1

0

以下是人们之前遇到的一些问题,sphinx_scopes这可能是这里的问题。

  • 人们在他们的sphinx_scopes. 您的作用域by_account是它的主要候选者,因此请尝试重命名它。我可以想象在派生类而不是基类中搞砸的情况。
  • 过去的范围问题已通过重新排序调用来解决,因此请尝试Admin.without_deleted.by_account(1). 不是修复,我知道。
  • 我还预测这是一个主键(即每个account_id最多一个)。如果是这样,这可以解释为什么选择过早获取它。UserAccountRails
于 2012-11-22T09:41:20.963 回答