Created
August 4, 2017 11:11
-
-
Save bogdan/eed4d23b7c1fe2325420b44725fdf68e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/models/custom_property.rb b/app/models/custom_property.rb | |
index eea3a8c70f..5763ecd547 100644 | |
--- a/app/models/custom_property.rb | |
+++ b/app/models/custom_property.rb | |
@@ -80,17 +80,12 @@ class CustomProperty < BaseModel | |
end || CustomProperty.new(key: key, value: existing_properties[key]&.first&.value) | |
target_property.person = person | |
target_property.visitor = visitor | |
- target_property.value = new_properties[key] if new_properties.has_key?(key) | |
- if target_property.value.nil? | |
- if target_property.persisted? # property had some value | |
- target_property.value = '' | |
- else | |
- next | |
- end | |
+ if new_properties.has_key?(key) && (new_properties[key] || target_property.persisted?) | |
+ target_property.value = new_properties[key].to_s | |
end | |
# Bringing property on top if not the most actual | |
target_property.updated_at = Time.zone.now unless existing_properties.fetch(key, []).first == target_property | |
- target_property.save! if target_property.changed? | |
+ target_property.save! if target_property.changed? && target_property.value | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment