我有一个包含两个整数字段的对象报告:月和年。我需要按“日期”排序
Report.desc(:year).desc(:month).each do |a|
puts a.year.to_s + " " + a.month.to_s
end
结果:
2011 12
2011 11
2012 7
2012 6
2012 5
2012 4
2012 3
2012 2
2012 1
虽然我想得到
2012 7
2012 6
2012 5
2012 4
2012 3
2012 2
2012 1
2011 12
2011 11
我究竟做错了什么?
Mongoid 标准如下所示:
irb(main):043:0> Report.desc(:year).desc(:month)
=> #<Mongoid::Criteria
selector: {},
options: {:sort=>{"year"=>-1, "month"=>-1}},
class: Report,
embedded: true>