2017-08-23 26 views
0

当使用带有从A到B的has_one关联(使用B具有belongs_to语句)的Thinking Sphinx对A进行索引时,可以在索引中使用has_many关联和join语句。当然,这会产生一个SphinxQL查询,它在B的主键上进行分组。但是,当我尝试使用与B上的索引相同的关联时,我无法明显使用belongs_to端的关联。我的问题是,是否有可能使用belongs_to关联,或者是否有解决方法?这里是我的代码的相关部分:使用ActiveRecord加入Thi​​nking Sphinx

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 
... 
+0

您可以在索引定义中明确使用belongs_to关联。它以什么方式不适合你? – pat

回答

0

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