使用ThinkingSphinx索引sql联接



我是思维狮身人面像的新手,我没有找到任何解决方案来帮助我使用思维狮身像索引左联接。

这是我想在斯芬克斯中索引的查询

Company.joins("left join award_judges on award_judges.company_id = companies.id").where("companies.company_type = 'investor' AND (award_judges.award_id = 6 OR award_judges.award_id IS NULL)").select("companies.id,companies.name, award_judges.judge_application_type,award_judges.judgement_status").order("award_judges.judge_application_type, award_judges.judgement_status")

在我的公司模型中,关联是

has_many :award_judges

您可以在索引定义中引用索引中的关联,并且还具有WHERE条件:

indexes award_judges.judgement_status, :as => :judgement_statuses
where "companies.company_type = 'investor' AND (award_judges.award_id = 6 OR award_judges.award_id IS NULL)"

最新更新