mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 23:06:50 +00:00
move @node assignment and the include_associations! call outside the cached response, since including associations produces the side-effect *actually* including the associations.
Previously, subsequent renders of a cached serializer would never include associations.
This commit is contained in:
parent
1a684927c4
commit
ab502f0c52
@ -353,13 +353,16 @@ module ActiveModel
|
|||||||
# Returns a hash representation of the serializable
|
# Returns a hash representation of the serializable
|
||||||
# object without the root.
|
# object without the root.
|
||||||
def serializable_hash
|
def serializable_hash
|
||||||
if perform_caching?
|
@node = if perform_caching?
|
||||||
cache.fetch expand_cache_key([self.class.to_s.underscore, cache_key, 'serializable-hash']) do
|
cache.fetch expand_cache_key([self.class.to_s.underscore, cache_key, 'serializable-hash']) do
|
||||||
_serializable_hash
|
_serializable_hash
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
_serializable_hash
|
_serializable_hash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
include_associations! if _embed
|
||||||
|
@node
|
||||||
end
|
end
|
||||||
|
|
||||||
def include_associations!
|
def include_associations!
|
||||||
@ -476,9 +479,7 @@ module ActiveModel
|
|||||||
|
|
||||||
def _serializable_hash
|
def _serializable_hash
|
||||||
return nil if @object.nil?
|
return nil if @object.nil?
|
||||||
@node = attributes
|
attributes
|
||||||
include_associations! if _embed
|
|
||||||
@node
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform_caching?
|
def perform_caching?
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user