mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Simplify Serializer#cached_attributes to take a fields argument
This commit is contained in:
parent
ba23de686d
commit
385abb4ba0
@ -208,17 +208,17 @@ module ActiveModel
|
||||
end
|
||||
end
|
||||
|
||||
def cached_attributes(options, cached_attributes, adapter_instance)
|
||||
def cached_attributes(fields, cached_attributes, adapter_instance)
|
||||
if self.class.cache_enabled?
|
||||
key = cache_key(adapter_instance)
|
||||
cached_attributes.fetch(key) do
|
||||
cache_check(adapter_instance) do
|
||||
attributes(options[:fields])
|
||||
attributes(fields)
|
||||
end
|
||||
end
|
||||
else
|
||||
cache_check(adapter_instance) do
|
||||
attributes(options[:fields])
|
||||
attributes(fields)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -33,7 +33,7 @@ module ActiveModelSerializers
|
||||
|
||||
def serializable_hash_for_single_resource(options)
|
||||
cached_attributes = instance_options[:cached_attributes] || {}
|
||||
resource = serializer.cached_attributes(options, cached_attributes, self)
|
||||
resource = serializer.cached_attributes(options[:fields], cached_attributes, self)
|
||||
relationships = resource_relationships(options)
|
||||
resource.merge(relationships)
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user