Skip to content

non-cacheable fields #3

Answered by ElMassimo
deepsystm asked this question in Q&A
Apr 20, 2022 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

Hi Vladimir! @deepsystm


How do I make fields in the serializer that are always obtained by querying a value rather than a cached version of the value?

By default, serializers do not cache any value, so every time the MixSerializer is used, it would call get_updated_data again.

If you share an example that's not working as expected in a public repo, I can take a look.


How to pass additional data to the serializer besides the serialization object itself?

Any additional options, such as current_user: current_user are available in an options hash:

class AlbumSerializer < Oj::Serializer
  def current_user
    options[:current_user]
  end
end

If it's something that you plan on using often…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@deepsystm
Comment options

@deepsystm
Comment options

@ElMassimo
Comment options

@deepsystm
Comment options

Answer selected by ElMassimo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1 on April 20, 2022 14:01.