我有以下类别模型:
class Category
include Mongoid::Document
include Mongoid::Tree
field :title, type: String
validates :title, presence: true, uniqueness: true, length: {minimum: 2}
end
我存储了以下测试数据:
Root 1
Leaf 1
Subleaf 1
Leaf 2
Root 2
Leaf 3
现在当我调用 Category.all 它返回:
Root 1
Leaf 2
Leaf 1
Root 2
Subleaf 1
Leaf 3
但我需要以下订购:
Root 1
Leaf 1
Subleaf 1
Leaf 2
Root 2
Leaf 3