作者:林小秋 | 来源:互联网 | 2023-09-18 12:01
Allow an ID of object to be customized directly on the serializer by
passing a block to
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.
Closes #315
该提问来源于开源项目:Netflix/fast_jsonapi
Thanks for merging this PR. I noticed this still doesn't exactly follow the same behaviour as
. You can't pass a custom
to the block like you can with
. It seems the code for handling
is quite separate from
but would it be possible to achieve the following?
1 2 3 4 5 6 7 8
| ruby
class SomeSerializer
include FastJsonapi::ObjectSerializer
set_id :id do |_object, params| # :id may be unnecessary
params[:id]
end
end |