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
I was trying to return a serializer with a relationship and I noticed that in the relationship field I was always getting { meta { included: false } }
At first, I thought it was not finding the correct serializer for the relationship... But after some time I realized that if I put the name of the model in camelCase in the included array it started working...
This is the index method in the controller:
def index
render jsonapi: Club.all, include: [:cover, :fieldFolder]
end
class SerializableFieldFolder < SerializableBase
attribute :club_id
belongs_to :club
end
class SerializableBase < JSONAPI::Serializable::Resource
extend JSONAPI::Serializable::Resource::KeyFormat
key_format ->(key) { key.to_s.camelize(:lower) }
type { @object.class.name.underscore.pluralize }
end
The thing is that I'm transforming the keys to camelCase in the base serializer.
Is this the correct way to transform the keys? Or I should do it in a different way?
If keys transformation is ok, I don't think that it should affect the format of the include array, maybe calling underscore for each included key fix the issue.
Thanks!
The text was updated successfully, but these errors were encountered:
Hello,
I was trying to return a serializer with a relationship and I noticed that in the relationship field I was always getting
{ meta { included: false } }
At first, I thought it was not finding the correct serializer for the relationship... But after some time I realized that if I put the name of the model in camelCase in the
included
array it started working...This is the index method in the controller:
These are the serializers:
The thing is that I'm transforming the keys to camelCase in the base serializer.
Is this the correct way to transform the keys? Or I should do it in a different way?
If keys transformation is ok, I don't think that it should affect the format of the include array, maybe calling
underscore
for each included key fix the issue.Thanks!
The text was updated successfully, but these errors were encountered: