lib/neo4j/active_rel/persistence.rb in neo4j-5.0.15 vs lib/neo4j/active_rel/persistence.rb in neo4j-5.1.0.rc.1

- old
+ new

@@ -45,11 +45,18 @@ end end # Same as #create, but raises an error if there is a problem during save. def create!(*args) - fail RelInvalidError, self unless create(*args) + props = args[0] || {} + relationship_props = extract_association_attributes!(props) || {} + new(props).tap do |obj| + relationship_props.each do |prop, value| + obj.send("#{prop}=", value) + end + obj.save! + end end end private @@ -68,13 +75,11 @@ def type_validation_error_message(node, type_class) "Node class was #{node.class} (#{node.class.object_id}), expected #{type_class} (#{type_class.object_id})" end - def _create_rel(from_node, to_node, *args) - props = self.class.default_property_values(self) - props.merge!(args[0]) if args[0].is_a?(Hash) + def _create_rel(from_node, to_node, props = {}) set_classname(props, true) if from_node.id.nil? || to_node.id.nil? fail RelCreateFailedError, "Unable to create relationship (id is nil). from_node: #{from_node}, to_node: #{to_node}" end @@ -89,9 +94,9 @@ .send(create_method, "n1-[r:`#{type}`]->n2") .with('r').set(r: props).pluck(:r).first end def create_method - self.class.unique? ? :create_unique : :create + self.class.creates_unique? ? :create_unique : :create end end end