2012-11-30 35 views
2

我正在嘗試使用solr搜索產品,它運行良好。除了我要限制的供應商,與has_and_belongs_to_many產品相關,利用供應商模式爲0或1Ruby on Rails包含的關聯中的太陽黑子solr條件

我的模型狀態字段有:

「Product.rb」

has_and_belongs_to_many :suppliers, :class_name => 'Company' 

searchable do 
    text :name 
    text :brand 
    text :description 
end 

「Company.rb」

attr_accessible :status 

has_and_belongs_to_many :products 

對於搜索我使用:

@search = Product.search(:include => :suppliers) do 
    fulltext params[:s] 
    with :status, 1 # This gives error as status is not a field in Product 
end 

如何僅包含狀態爲1的供應商?

回答

0

你錯過了在搜索

searchable do 
    text :name 
    text :brand 
    text :description 
    boolean :status 
end 
狀態