3
复杂的搜索我有以下模式设置轨与祖先
class Category < ActiveRecord::Base
has_ancestry :cache_depth => true, :depth_cache_column => :depth
has_many :watches, :dependent => :destroy
has_many :products, :through => :watches
end
class Watch < ActiveRecord::Base
belongs_to :category
has_many :products
end
class Product < ActiveRecord::Base
belongs_to :watch, :counter_cache => true
belongs_to :category
end
我需要找到通过类别名称的产品。类别有2层深(树结构)。 1 - 级是一个制造,2 - 系列。现在IM建立这种类型的搜索查询与meta_search
宝石
@products = (Product.search :watch_category_name_contains => params[:search]).all.paginate(:page => params[:page])
这个工程的帮助下,用serie_name返回所有产品。但是手表总是只包含2级分类(serie)的category_id,而im需要能够通过make(1级分类)搜索产品。我如何构建这种类型的查询?谢谢!