-
Notifications
You must be signed in to change notification settings - Fork 36
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
Serialization level setting #55
Comments
@railsfactory-selva do you have any example why you would like to set filtering globally for all serializers? and can you point me to AMS example for setting it globally? |
@yosiat We would like to have one-level serializer by default, and include nesting just whenever required as like AMS (or) there should be option to change it to 'one level' globally which would be helpful for many people. In AMS, by default it's one-level and we can change it to deep nesting globally, by adding below code at initializers |
This would also help me out a lot in trying to migrate off of AMS |
@yosiat First of all, I've been playing with the library for a few hours and I'm really liking it so far. It takes all of the bloat and bad performance out of AMS, and keeps the good bits! In particular, I like that Panko does not hack itself into In order for me to transition off AMS I need to be able to specify
and
And a few other variations but I can never get the attributes/relationships of I'll always get back:
Where I want to see:
I have to do this because The way AMS works now is I can pass in a string such as
This is how AMS parses the string: https://github.com/jsonapi-rb/jsonapi-renderer/blob/master/lib/jsonapi/include_directive.rb And details on how it works: https://github.com/rails-api/active_model_serializers/blob/v0.10.6/docs/general/adapters.md#include-option AMS splits the attributes and relationships into two separate options: Thanks! |
I've also tried passing it into the
The subject in question is an I would expect this to only include the In other words, if I pass in a And if the Thoughts? |
Hello @yosiat ! Thanks so much for this gem. Definitely a better alternative to AMS and keeping it minimalistic allows developers to customize its serializer a lot. Hello @jeffblake ! Thank you so much for posting this. I have been tearing my hair out with this issue. So definitely +1 this problem. But the funny thing is I actually have two serializers. One works and the other doesn't. And the nature of both these serializers have been written in a similar format. DOESNT WORK => NOTE: Customer model is inherited from base User model. I am not sure whether that makes a difference. NOTE 2: So sorry for the screenshot. I cant seem to code it out using the tildas. The other one that works is of similar nature. Has a serializer that references another one. And in the class method, the association is filtered. Apologies beforehand if the code snippet is not descriptive enough. Please let me know if anything is vague and will try to clarify! Thanks beforehand! |
Hey @jeffblake ! I was able to figure this out. This has been written somewhere (in fine print :P) in the docs. But if you try the following, it should work =>
As per docs written in the Associations sections - Let's dissect only option we passed - instance - list of attributes (and associations) we want to serializer for current instance of the serializer, in this case - PostSerializer. |
Serialization level in AMS is set to ‘One level’ by default, which we can change it to deep nesting from config globally.
Do we have similar setting in Panko? If I'm not wrong, it seems Panko does deep nesting by default unless mentioned while invoking serializer like below
Panko::ArraySerializer.new(posts, only: {
instance: [:title, :body, :author, :comments],
author: [:id],
comments: {
instance: [:id, :author],
author: [:name]
}
})
It would be great, if we have config kind of stuff to set serialization level globally.
The text was updated successfully, but these errors were encountered: