mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Optimise serializable_hash when options are empty
This reverts8538dfdc08
, which broke the activemodel-serializers-xml gem. We can still get most of the benefit by applying the optimisation from7b39197742
to empty hashes as well as nil. This has the additional benefit of retaining the optimisation when the user passes an empty options hash.
This commit is contained in:
parent
e4b6c719cd
commit
7e14c16cc0
1 changed files with 2 additions and 2 deletions
|
@ -123,7 +123,7 @@ module ActiveModel
|
|||
def serializable_hash(options = nil)
|
||||
attribute_names = attributes.keys
|
||||
|
||||
return serializable_attributes(attribute_names) unless options
|
||||
return serializable_attributes(attribute_names) if options.blank?
|
||||
|
||||
if only = options[:only]
|
||||
attribute_names &= Array(only).map(&:to_s)
|
||||
|
@ -179,7 +179,7 @@ module ActiveModel
|
|||
return unless includes = options[:include]
|
||||
|
||||
unless includes.is_a?(Hash)
|
||||
includes = Hash[Array(includes).flat_map { |n| n.is_a?(Hash) ? n.to_a : [[n, nil]] }]
|
||||
includes = Hash[Array(includes).flat_map { |n| n.is_a?(Hash) ? n.to_a : [[n, {}]] }]
|
||||
end
|
||||
|
||||
includes.each do |association, opts|
|
||||
|
|
Loading…
Reference in a new issue