Answers for "rails serializer for has many"

0

how to display the has_many in the api serializer rails

class ProjectGroupSerializer < ActiveModel::Serializer
  attributes :id, :name, :description, :projects

  def projects
    object.projects.map do |project|
      ::ProjectSerializer.new(project).attributes
    end
  end
end
Posted by: Guest on December-04-2020

Code answers related to "rails serializer for has many"

Browse Popular Code Answers by Language