Module: ActiveGraph::Node::Dependent::QueryProxyMethods

Included in:
Query::QueryProxy
Defined in:
lib/active_graph/node/dependent/query_proxy_methods.rb

Overview

methods used to resolve association dependencies

Instance Method Summary collapse

Instance Method Details

#each_for_destruction(owning_node) ⇒ Object

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. but this is not always available, so we require it explicitly.

Parameters:

  • owning_node (#dependent_children)

    source_object The node that called this method. Typically, we would use QueryProxy's `source_object` method



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/active_graph/node/dependent/query_proxy_methods.rb', line 10

def each_for_destruction(owning_node)
  target = owning_node.called_by || owning_node
  objects = pluck(identity).compact.reject do |obj|
    target.dependent_children.include?(obj)
  end

  objects.each do |obj|
    obj.called_by = target
    target.dependent_children << obj
    yield obj
  end
end

#unique_nodes(association, self_identifer, other_node, other_rel, ids = []) ⇒ ActiveGraph::Node::Query::QueryProxy

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.

Parameters:

  • association (ActiveGraph::Node::HasN::Association)

    The Association object used throughout the match.

  • other_node (String, Symbol)

    The identifier to use for the other end of the chain.

  • other_rel (String, Symbol)

    The identifier to use for the relationship in the optional match.

Returns:



29
30
31
32
33
34
# File 'lib/active_graph/node/dependent/query_proxy_methods.rb', line 29

def unique_nodes(association, self_identifer, other_node, other_rel, ids = [])
  fail 'Only supported by in QueryProxy chains started by an instance' unless source_object
  return false if send(association.name).empty?
  unique_nodes_query(association, self_identifer, other_node, other_rel, ids)
    .proxy_as(association.target_class, other_node)
end