From ab502f0c522c6f1342997041a99d274fa5029cd5 Mon Sep 17 00:00:00 2001 From: Kieran Huggins Date: Fri, 16 Oct 2015 16:05:38 -0400 Subject: [PATCH] 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. --- lib/active_model/serializer.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/active_model/serializer.rb b/lib/active_model/serializer.rb index 73b6ba42..c202610e 100644 --- a/lib/active_model/serializer.rb +++ b/lib/active_model/serializer.rb @@ -353,13 +353,16 @@ module ActiveModel # Returns a hash representation of the serializable # object without the root. 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 _serializable_hash end else _serializable_hash end + + include_associations! if _embed + @node end def include_associations! @@ -476,9 +479,7 @@ module ActiveModel def _serializable_hash return nil if @object.nil? - @node = attributes - include_associations! if _embed - @node + attributes end def perform_caching?