mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 23:06: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
|
||||||
end
|
end
|
||||||
|
|
||||||
def cached_attributes(options, cached_attributes, adapter_instance)
|
def cached_attributes(fields, cached_attributes, adapter_instance)
|
||||||
if self.class.cache_enabled?
|
if self.class.cache_enabled?
|
||||||
key = cache_key(adapter_instance)
|
key = cache_key(adapter_instance)
|
||||||
cached_attributes.fetch(key) do
|
cached_attributes.fetch(key) do
|
||||||
cache_check(adapter_instance) do
|
cache_check(adapter_instance) do
|
||||||
attributes(options[:fields])
|
attributes(fields)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
cache_check(adapter_instance) do
|
cache_check(adapter_instance) do
|
||||||
attributes(options[:fields])
|
attributes(fields)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -33,7 +33,7 @@ module ActiveModelSerializers
|
|||||||
|
|
||||||
def serializable_hash_for_single_resource(options)
|
def serializable_hash_for_single_resource(options)
|
||||||
cached_attributes = instance_options[:cached_attributes] || {}
|
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)
|
relationships = resource_relationships(options)
|
||||||
resource.merge(relationships)
|
resource.merge(relationships)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user