lib/neo4j/shared/persistence.rb in neo4j-8.0.0.alpha.12 vs lib/neo4j/shared/persistence.rb in neo4j-8.0.0.rc.1
- old
+ new
@@ -8,15 +8,21 @@
def props_for_persistence
_persisted_obj ? props_for_update : props_for_create
end
def update_model
- return if !changed_attributes || changed_attributes.empty?
- neo4j_query(query_as(:n).set(n: props_for_update))
+ return if skip_update?
+ props = props_for_update
+ neo4j_query(query_as(:n).set(n: props))
+ _persisted_obj.props.merge!(props)
changed_attributes.clear
end
+ def skip_update?
+ changed_attributes.blank?
+ end
+
# Returns a hash containing:
# * All properties and values for insertion in the database
# * A `uuid` (or equivalent) key and value
# * Timestamps, if the class is set to include them.
# Note that the UUID is added to the hash but is not set on the node.
@@ -64,18 +70,18 @@
# Convenience method to set attribute and #save at the same time
# @param [Symbol, String] attribute of the attribute to update
# @param [Object] value to set
def update_attribute(attribute, value)
- send("#{attribute}=", value)
+ write_attribute(attribute, value)
self.save
end
# Convenience method to set attribute and #save! at the same time
# @param [Symbol, String] attribute of the attribute to update
# @param [Object] value to set
def update_attribute!(attribute, value)
- send("#{attribute}=", value)
+ write_attribute(attribute, value)
self.save!
end
def create_or_update
# since the same model can be created or updated twice from a relationship we have to have this guard