class ActiveGraph::Node::HasN::Association::RelFactory

Public Class Methods

create(start_object, other_node_or_nodes, properties, association) click to toggle source
   # File lib/active_graph/node/has_n/association/rel_factory.rb
 9 def self.create(start_object, other_node_or_nodes, properties, association)
10   factory = new(start_object, other_node_or_nodes, properties, association)
11   factory._create_relationship
12 end
new(start_object, other_node_or_nodes, properties, association) click to toggle source
   # File lib/active_graph/node/has_n/association/rel_factory.rb
21 def initialize(start_object, other_node_or_nodes, properties, association)
22   @start_object = start_object
23   @other_node_or_nodes = other_node_or_nodes
24   @properties = properties
25   @association = association
26 end

Public Instance Methods

_create_relationship() click to toggle source
   # File lib/active_graph/node/has_n/association/rel_factory.rb
14 def _create_relationship
15   creator = association.relationship_class ? :rel_class : :factory
16   send(:"_create_relationship_with_#{creator}")
17 end

Private Instance Methods

_create_relationship_with_factory() click to toggle source
   # File lib/active_graph/node/has_n/association/rel_factory.rb
35 def _create_relationship_with_factory
36   Array(other_node_or_nodes).each do |other_node|
37     wrapper = _rel_wrapper(properties)
38     base = _match_query(other_node, wrapper)
39     factory = ActiveGraph::Shared::RelQueryFactory.new(wrapper, wrapper.rel_identifier)
40     factory.base_query = base
41     factory.query.exec
42   end
43 end
_create_relationship_with_rel_class() click to toggle source
   # File lib/active_graph/node/has_n/association/rel_factory.rb
28 def _create_relationship_with_rel_class
29   Array(other_node_or_nodes).each do |other_node|
30     node_props = _nodes_for_create(other_node, :from_node, :to_node)
31     association.relationship_class.create!(properties.merge(node_props))
32   end
33 end
_match_query(other_node, wrapper) click to toggle source
   # File lib/active_graph/node/has_n/association/rel_factory.rb
45 def _match_query(other_node, wrapper)
46   nodes = _nodes_for_create(other_node, wrapper.from_node_identifier, wrapper.to_node_identifier)
47   ActiveGraph::Base.new_query.match_nodes(nodes)
48 end
_nodes_for_create(other_node, from_node_id, to_node_id) click to toggle source
   # File lib/active_graph/node/has_n/association/rel_factory.rb
50 def _nodes_for_create(other_node, from_node_id, to_node_id)
51   nodes = [@start_object, other_node]
52   nodes.reverse! if association.direction == :in
53   {from_node_id => nodes[0], to_node_id => nodes[1]}
54 end
_rel_wrapper(properties) click to toggle source
   # File lib/active_graph/node/has_n/association/rel_factory.rb
56 def _rel_wrapper(properties)
57   ActiveGraph::Node::HasN::Association::RelWrapper.new(association, properties)
58 end