📜  如何在 api 序列化程序 rails 中显示 has_many - Ruby 代码示例

📅  最后修改于: 2022-03-11 15:04:46.700000             🧑  作者: Mango

代码示例1
class ProjectGroupSerializer < ActiveModel::Serializer
  attributes :id, :name, :description, :projects

  def projects
    object.projects.map do |project|
      ::ProjectSerializer.new(project).attributes
    end
  end
end