FIX: JSON custom fields incorrectly being converted to an array.

https://meta.discourse.org/t/custom-fields-simultaneous-save-with-json-becomes-an-array/73647
This commit is contained in:
Guo Xiang Tan
2017-11-08 11:10:20 +08:00
parent cd744d58f8
commit 4bb454d889
2 changed files with 30 additions and 7 deletions

View File

@@ -161,7 +161,7 @@ module HasCustomFields
array_fields = {}
_custom_fields.each do |f|
_custom_fields.reload.each do |f|
if dup[f.name].is_a? Array
# we need to collect Arrays fully before we can compare them
if !array_fields.has_key?(f.name)
@@ -171,7 +171,7 @@ module HasCustomFields
end
elsif dup[f.name].is_a? Hash
if dup[f.name].to_json != f.value
f.destroy
f.destroy!
else
dup.delete(f.name)
end
@@ -180,7 +180,7 @@ module HasCustomFields
self.class.append_custom_field(t, f.name, f.value)
if dup[f.name] != t[f.name]
f.destroy
f.destroy!
else
dup.delete(f.name)
end
@@ -198,11 +198,12 @@ module HasCustomFields
dup.each do |k, v|
if v.is_a? Array
v.each { |subv| _custom_fields.create(name: k, value: subv) }
elsif v.is_a? Hash
_custom_fields.create(name: k, value: v.to_json)
v.each { |subv| _custom_fields.create!(name: k, value: subv) }
else
_custom_fields.create(name: k, value: v)
_custom_fields.create!(
name: k,
value: v.is_a?(Hash) ? v.to_json : v
)
end
end