You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
this PR is about to keep the namespace in record_type. I believe it should be like this because the namespace is an important part of the class name and without it the record_type is not assured to be unique like it's supposed to be.
We intensively use namespace and we have a few classes with the same name in different namespace and so it can create some confusion for our frontend developers.
I think it should at least be a global option, and I don't want to set set_type on every serializer and record_type on every relation (by the way it's strange to have to set again record_type on relations).
I'd like to disagree here. I think it's pretty common to have namespace scoped serializers/models and not reflect it in the record type.
I think it should at least be a global option, and I don't want to set set_type on every serializer and record_type on every relation
You don't have to set it for every serializer if you create a base serializer class which you inherit for the rest of your implemented serializers.
Consider something like this:
# app/serializers/base_serializer.rb
class BaseSerializer
include FastJsonapi::ObjectSerializer
def self.set_type
super # or change it for your use-case
end
# ... any other customization ...
end
next
# app/serializers/tag_serializer.rb
class TagSerializer < BaseSerializer
# ...
end
(by the way it's strange to have to set again record_type on relations)
It's a small trade-off which helps improve the performance a lot.
Hi,
for the base class that's kind of what I did, except I have overridden the reflected_record_type method.
For my case we have a project with around 200 models / tables and the namespace is used to classify / clarify models.
Like we have a model Supplier::Profile and a Restaurant::Profile (which have no common logic) and our frontend developers read the type field from the JSON which supposed to be unique by model.
The type field is supposed to identify uniquely the resource model, I don't know how you use namespace but it means you could have to 2 serializers with the same type, which doesn't follow JSON API specification from what I understand.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
this PR is about to keep the namespace in
record_type. I believe it should be like this because the namespace is an important part of the class name and without it the record_type is not assured to be unique like it's supposed to be.We intensively use namespace and we have a few classes with the same name in different namespace and so it can create some confusion for our frontend developers.
I think it should at least be a global option, and I don't want to set
set_typeon every serializer andrecord_typeon every relation (by the way it's strange to have to set againrecord_typeon relations).