-
Hi ElMassimo, thanks for your work, amazing and fast lib! I have a few questions:
class MixSerializer < Oj::Serializer
has_one :user, serializer: UserListItemSerializer
attributes :id,
:field_that_never_been_cached,
:title
attribute \
def field_that_never_been_cached
get_updated_data
end
end
render json: AlbumSerializer.one(album, current_user: current_user) if signed_in? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi Vladimir! @deepsystm
By default, serializers do not cache any value, so every time the If you share an example that's not working as expected in a public repo, I can take a look.
Any additional options, such as class AlbumSerializer < Oj::Serializer
def current_user
options[:current_user]
end
end If it's something that you plan on using often, you can define helpers in a Also, if the additional data is not optional, you might want to use def current_user
options.fetch(:current_user)
end That way it will fail early if the serializer is used incorrectly. |
Beta Was this translation helpful? Give feedback.
Hi Vladimir! @deepsystm
By default, serializers do not cache any value, so every time the
MixSerializer
is used, it would callget_updated_data
again.If you share an example that's not working as expected in a public repo, I can take a look.
Any additional options, such as
current_user: current_user
are available in anoptions
hash:If it's something that you plan on using often…