假设我有一个属于建筑模型的房间模型。建筑与类别之间存在has_many关系。
我正在尝试找出如何索引房间模型,以便搜索category_id =1将返回任何房间,在任何建筑中碰巧分配了该类别。同样,一个建筑可以有多个类别。
谢谢!
发布于 2009-07-14 21:24:53
首先,您需要在Post模型中设置如下索引:
define_index do
# fields go here
# the important attribute for your filter:
has building.categories(:id), :as => :category_ids
end
至于搜索:
Room.search 'query', :with => {:category_ids => 1}
如果这不是你想要的,请告诉我。
https://stackoverflow.com/questions/1127450
复制相似问题