我试图将mongoid标准联系起来。
如果我获取单 "$in"
(或:field.in
,Model.any_in
)条件,我会得到预期结果。
当我像下面的例子中那样组合它们时,我的结果是不可取的。
rSpec示例
@person = Fabricate :person, categories: [@c1], services: [@s1]
@person2 = Fabricate :person
get 'person_search', categories: "#{@c1.id}", services: "#{@s1.id}"
expect(assigns(:person)).to include(@person)
expect(assigns(:person)).to_not include(@person2)
。在
query = Person.where(country: "AT")
query = query.in(:category_ids => categories.collect(&:_id)) if categories.present?
query = query.in(:service_ids => services.collect(&:_id)) if services.present?
@people = query.map do |person|
person
end
我也试过
query = Person.where(country: "AT")
query = query.where(:category_ids.in => categories.collect(&:_id)) if categories.present?
query = query.where(:service_ids.in => services.collect(&:_id)) if services.present?
@people = query.map do |person|
person
end
这也不起作用:
query = Person.where(country: "AT")
query = query.all(:category_ids.in => categories.collect(&:_id)) if categories.present?
query = query.all(:service_ids.in => services.collect(&:_id)) if services.present?
@people = query.map do |person|
person
end