lib/neo4j/active_node/property.rb in neo4j-4.1.5 vs lib/neo4j/active_node/property.rb in neo4j-5.0.0.rc.1
- old
+ new
@@ -3,20 +3,28 @@
extend ActiveSupport::Concern
include Neo4j::Shared::Property
def initialize(attributes = {}, options = {})
super(attributes, options)
-
- send_props(@relationship_props) if persisted? && !@relationship_props.nil?
+ @attributes ||= self.class.attributes_nil_hash.dup
+ send_props(@relationship_props) if _persisted_obj && !@relationship_props.nil?
end
module ClassMethods
- # Extracts keys from attributes hash which are relationships of the model
+ # Extracts keys from attributes hash which are associations of the model
# TODO: Validate separately that relationships are getting the right values? Perhaps also store the values and persist relationships on save?
def extract_association_attributes!(attributes)
- attributes.keys.each_with_object({}) do |key, association_props|
- association_props[key] = attributes.delete(key) if self.association?(key)
+ return unless contains_association?(attributes)
+ attributes.each_with_object({}) do |(key, _), result|
+ result[key] = attributes.delete(key) if self.association?(key)
end
+ end
+
+ private
+
+ def contains_association?(attributes)
+ attributes.each_key { |key| return true if associations_keys.include?(key) }
+ false
end
end
end
end