scinote-web/app/serializers/api/v1/protocol_serializer.rb

18 lines
617 B
Ruby
Raw Normal View History

# frozen_string_literal: true
module Api
module V1
class ProtocolSerializer < ActiveModel::Serializer
type :protocols
attributes :id, :name, :authors, :description, :protocol_type
has_many :protocol_keywords,
2018-10-07 19:28:29 +08:00
key: :keywords,
serializer: ProtocolKeywordSerializer,
class_name: 'ProtocolKeyword',
unless: -> { object.protocol_keywords.empty? }
has_many :steps, serializer: StepSerializer, if: -> { object.steps.any? }
belongs_to :parent, serializer: ProtocolSerializer, if: -> { object.parent.present? }
end
end
end