【问题标题】:Using ActiveRecord joins with Thinking Sphinx使用 ActiveRecord 与 Thinking Sphinx 连接
【发布时间】:2017-08-23 16:21:07
【问题描述】:

当使用 Thinking Sphinx 与从类 A 到 B 的 has_one 关联(B 具有belongs_to 语句),在 A 上建立索引时,可以在索引中使用 has_many 关联和 join 语句。当然,这会导致 SphinxQL 查询按 B 的主键分组。但是,当我尝试使用与 B 上的索引相同的关联时,我显然无法在 belongs_to 端使用关联。我的问题是,是否可以使用 belongs_to 关联,或者是否有解决方法?以下是我的代码的相关部分:

class IdentAssociation < ActiveRecord::Base
  has_many :donees, :foreign_key => :ident_id, :class_name => "Donees"
...

class Donees < ActiveRecord::Base
  belongs_to :ident_association, :foreign_key => :ident_id
...

ThinkingSphinx::Index.define :donees, :with => :active_record do
  join ident_association
...

【问题讨论】:

  • 您绝对可以在索引定义中使用belongs_to 关联。它在哪些方面不适合您?

标签: ruby-on-rails thinking-sphinx


【解决方案1】:

是的,我想我一定是打错了协会的名称。我还遇到了一些其他问题,例如 sphinx 抱怨缺少 sphinx_internal_class_name;但这超出了范围。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多