Mongoid 5 has_many命令

时间:2015-10-07 20:12:37

标签: ruby-on-rails mongodb mongoid

我有以下设置:

class Evaluation
  include Mongoid::Document
  default_scope -> { order("_id ASC") }

  has_many :children, order: "position ASC"
end

class Child
  include Mongoid::Document
  default_scope -> { order("_id ASC") }

  field position, type: Integer, default: 0
end

当我致电evaluation.children时,position订单不受尊重。我该怎么办?

1 个答案:

答案 0 :(得分:2)

这对我有用:

has_many :children, order: :position.asc