Rails 4:在序列化程序中订购 has_many

Jer*_*mas 4 serialization ruby-on-rails has-many ruby-on-rails-4

我有一个带有has_many关联的序列化程序,我想订购依赖模型。由于某种原因,我收到一个undefined method key?'错误:

class API::ClientSerializer < ActiveModel::Serializer
    has_many :check_ins, -> { order(:week) }
end
Run Code Online (Sandbox Code Playgroud)

我还可以如何按周订购 check_ins?

fab*_*bro 11

class API::ClientSerializer < ActiveModel::Serializer
  has_many :check_ins do
    object.check_ins.order(:week)
  end 
end
Run Code Online (Sandbox Code Playgroud)