lib/neo4j/active_node/has_n.rb in activegraph-10.0.0.pre.alpha.7 vs lib/neo4j/active_node/has_n.rb in activegraph-10.0.0.pre.alpha.8

- old
+ new

@@ -227,30 +227,29 @@ fresh_association_proxy(name, options) end end end - def validate_reverse_has_one_core_rel(association, other_node) - return unless Neo4j::Config[:enforce_has_one] + def delete_reverse_has_one_core_rel(association) reverse_assoc = reverse_association(association) - validate_has_one_rel!(reverse_assoc, other_node) if reverse_assoc && reverse_assoc.type == :has_one + delete_has_one_rel!(reverse_assoc) if reverse_assoc && reverse_assoc.type == :has_one end def reverse_association(association) reverse_assoc = self.class.associations.find do |_key, assoc| association.inverse_of?(assoc) || assoc.inverse_of?(association) end reverse_assoc && reverse_assoc.last end - def validate_reverse_has_one_active_rel(active_rel, direction, other_node) + def delete_reverse_has_one_active_rel(active_rel, direction, other_node) rel = active_rel_corresponding_rel(active_rel, direction, other_node.class) - validate_has_one_rel!(rel.last, other_node) if rel && rel.last.type == :has_one + delete_has_one_rel!(rel.last) if rel && rel.last.type == :has_one end - def validate_has_one_rel!(rel, other_node) - raise_error = (node = send(rel.name.to_s)) && node != other_node - fail(HasOneConstraintError, "node #{self.class}##{neo_id} has a has_one relationship with #{other_node.class}##{other_node.neo_id}") if raise_error + def delete_has_one_rel!(rel) + send("#{rel.name}", :n, :r, chainable: true).query.delete(:r).exec + association_proxy_cache.clear end def active_rel_corresponding_rel(active_rel, direction, target_class) self.class.associations.find do |_key, assoc| assoc.relationship_class_name == active_rel.class.name ||