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
Currently we allow to customize any attribute by using blocks. I would like to extend the same behaviour to ids. Currently the only way to customize id is by using set_id :custom_id but this specifies an alternative method in the object. Instead, I would like to be able to customize id right here in the serializer, using something like this:
class MovieSerializer
include FastJsonapi::ObjectSerializer
attributes :name, :year
set_id do |record|
"This will be a string ID with #{record.id} inside"
end
This is useful in situations when you have different types of objects (say, Movie, MovieBuilder, BaseMovie) being serialized using the same serializer (GeneralMovieSerializer), and you want to unify their ids setting code. What do you think?
The text was updated successfully, but these errors were encountered:
Allow an ID of object to be customized directly on the serializer by
passing a block to `set_id` as opposed to only through a model property.
We already allow for attributes that do not have a model property of the
same name to be customized directly on the serializer using a block.
ClosesNetflix#315
larissa
added a commit
to larissa/fast_jsonapi
that referenced
this issue
Oct 5, 2018
Allow an ID of object to be customized directly on the serializer by
passing a block to `set_id` as opposed to only through a model property.
We already allow for attributes that do not have a model property of the
same name to be customized directly on the serializer using a block.
ClosesNetflix#315
Currently we allow to customize any attribute by using blocks. I would like to extend the same behaviour to ids. Currently the only way to customize id is by using
set_id :custom_id
but this specifies an alternative method in the object. Instead, I would like to be able to customize id right here in the serializer, using something like this:This is useful in situations when you have different types of objects (say,
Movie
,MovieBuilder
,BaseMovie
) being serialized using the same serializer (GeneralMovieSerializer
), and you want to unify their ids setting code. What do you think?The text was updated successfully, but these errors were encountered: