Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify serializer inside serializer file #54

Open
Kadaaran opened this issue Sep 11, 2019 · 1 comment
Open

Specify serializer inside serializer file #54

Kadaaran opened this issue Sep 11, 2019 · 1 comment

Comments

@Kadaaran
Copy link

Hi there ☀️

Is there a way I can choose inside a serializer to render another serializer based on an attribute ?
Here is my code which is triggered into another serializer with has_many :activities, each_serializer: ActivitySerializer

class ActivitySerializer < Panko::Serializer
  attributes :id, :name, :max_capacity

  has_many :levels, each_serializer: LevelSerializer
end

But I'd like to filter has_many: levels based on another attribute called organization inside Level or at least to choose which levels I want to return.

Is it possible ?

Thanks again !

@yosiat
Copy link
Owner

yosiat commented Jan 11, 2020

@Kadaaran Hi!

If I understand you correctly you want to change the serializer of "levels" instead of LevelSerializer use other serializer based on level attributes?

If so, currently it's not supported since Panko don't have "dynamic runtime", Panko decides which serializers to choose before starting the serialization to optimize for performance.

It's possible to implement this with a bit of hack and not a natural way currently. If this feature is blocking you from using Panko, let's discuss on a proper solution and I will be happy to accept a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants