Skip to content

Add context to relations has_one/has_many #151

@rus-max

Description

@rus-max

Hi!

Is it possible to add context to relations has_one/has_many?

class PostSerializer < Panko::Serializer
  attributes :context_attribute

  def context_attribute
    context[:date] || object.date
  end
end

class UserSerializer < Panko::Serializer
  attributes :name, :address
  has_many :posts, serializer: PostSerializer, context: { date: object.date }
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions