2014-12-10 3 views
1

내 모델 : 난 인덱스에만 항목 group.disabled 수있는 방법생각 스핑크스 인덱서 조건

class Item < ActiveRecord::Base 
    belongs_to :group 
    scope :able, ->{joins(:group).where(:groups => {:disabled => [nil,false]}).order("position")} 
end 

class Group < ActiveRecord::Base 
    has_many :items 
    scope :able, ->{ where(disabled: [false,nil]).order('position') } 
end 

내 item_index.rb

ThinkingSphinx::Index.define :item, :with => :active_record do 
    indexes title 
    # attributes 
    has created_at, updated_at, group_id, position 
end 

는 허위 또는 전무하다. 경우에

예 : ID로

ThinkingSphinx::Index.define :item, :with => :active_record do 
    where "id = 1" 
    indexes title 
    # attributes 
    has created_at, updated_at, group_id, position 
end 

이 의지 만 색인 항목 = 색인 정의에서 1

답변

1

:

# force join on groups table: 
join group 

# PostgreSQL 
where "disabled = 'f' OR disabled IS NULL" 

# MySQL 
where "disabled = 0 OR disabled IS NULL" 

내가 매우 디폴트 값을 갖는에 권 해드립니다 비활성화 된 열에 대해 true 또는 false를 지정하여 null 값을 피할 수 있습니다.

+0

그룹 테이블의 열이 비활성화되었습니다. 나는 "groups.disabled = 'f'"와 같은 것을 필요로한다. – Denis

+0

Item.joins (: group) .where (: groups => {: disabled => [nil, false]}),이 항목 만 색인화해야합니다. – Denis