2016-03-22 69 views
0

我已经定义了以下范围(在我的模型中)来帮助我过滤出某些不需要的嵌套数据。使用红宝石mongoid gem过滤嵌套属性

scope :active_inactive, -> { self.in({ 
     state: ["current"], 
     "events.type" => [ 
     :active, 
     :inactive, 
     ] 
    }).desc(:created_at) 
    } 

当我运行这个时,我得到的结果是包含像这个范围不应该包含的“in_progress”其他事件。

回答

1

我觉得你的代码应该被改写成

scope :active_inactive, -> { 
    self.where(:state.in => ["current"], :"events.type".in =>["active","inactive"]}).desc(:created_at) 
} 
+0

几乎有@vitali –