我正在使用mongoid_nested_set,我该如何简化这段代码:
category.ancestors.where(depth: 3).first
以前我用过:
category.ancestors[3]
但这似乎不适用于mongoid 3.1.5 / rails 3.2.13 / ruby 1.9.3 / acticeadmin-mongoid 0.3.0
答案 0 :(得分:1)
您使用的是祖先吗?
如果这样做,您可以使用他们的命名范围 在这种情况下
category.ancestors.to_depth(3) # Return nodes up to depth 3 (1 and 2 also included)
category.ancestors.at_depth(depth) # Return nodes with the exact depth of 3
如README中所示。
答案 1 :(得分:0)
最终罪魁祸首是acticeadmin_mongoid 0.3.0,我删除了它,一切正常。