module Neo4j::ActiveNode::Dependent::QueryProxyMethods

methods used to resolve association dependencies

Public Instance Methods

each_for_destruction(owning_node) { |obj| ... } click to toggle source

Used as part of `dependent: :destroy` and may not have any utility otherwise. It keeps track of the node responsible for a cascading `destroy` process. @param owning_node [#dependent_children] source_object The node that called this method. Typically, we would use QueryProxy's `source_object` method but this is not always available, so we require it explicitly.

   # File lib/neo4j/active_node/dependent/query_proxy_methods.rb
10 def each_for_destruction(owning_node)
11   target = owning_node.called_by || owning_node
12   objects = pluck(identity).compact.reject do |obj|
13     target.dependent_children.include?(obj)
14   end
15 
16   objects.each do |obj|
17     obj.called_by = target
18     target.dependent_children << obj
19     yield obj
20   end
21 end
unique_nodes(association, self_identifer, other_node, other_rel) click to toggle source

This will match nodes who only have a single relationship of a given type. It's used by `dependent: :delete_orphans` and `dependent: :destroy_orphans` and may not have much utility otherwise. @param [Neo4j::ActiveNode::HasN::Association] association The Association object used throughout the match. @param [String, Symbol] other_node The identifier to use for the other end of the chain. @param [String, Symbol] other_rel The identifier to use for the relationship in the optional match. @return [Neo4j::ActiveNode::Query::QueryProxy]

   # File lib/neo4j/active_node/dependent/query_proxy_methods.rb
29 def unique_nodes(association, self_identifer, other_node, other_rel)
30   fail 'Only supported by in QueryProxy chains started by an instance' unless source_object
31   return false if send(association.name).empty?
32   unique_nodes_query(association, self_identifer, other_node, other_rel)
33     .proxy_as(association.target_class, other_node)
34 end

Private Instance Methods

unique_nodes_query(association, self_identifer, other_node, other_rel) click to toggle source
   # File lib/neo4j/active_node/dependent/query_proxy_methods.rb
38 def unique_nodes_query(association, self_identifer, other_node, other_rel)
39   query.with(identity).proxy_as_optional(source_object.class, self_identifer)
40        .send(association.name, other_node, other_rel)
41        .query
42        .with(other_node)
43        .match("()#{association.arrow_cypher(:orphan_rel)}(#{other_node})")
44        .with(other_node, count: 'count(*)')
45        .where('count = {one}', one: 1)
46        .break
47 end