Module: Neo4j::ActiveNode::Query::QueryProxyEagerLoading

Included in:
QueryProxy
Defined in:
lib/neo4j/active_node/query/query_proxy_eager_loading.rb

Defined Under Namespace

Classes: AssociationTree, IdentityMap

Instance Method Summary collapse

Instance Method Details

#association_tree_classObject


92
93
94
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 92

def association_tree_class
  AssociationTree
end

#firstObject


100
101
102
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 100

def first
  (query.clause?(:order) ? self : order(order_property)).limit(1).to_a.first
end

#perform_queryObject


61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 61

def perform_query
  @_cache = IdentityMap.new
  build_query
    .map do |record, eager_data|
    cache_and_init(record, with_associations_tree)
    eager_data.zip(with_associations_tree.paths.map(&:last)).each do |eager_records, element|
      eager_records.first.zip(eager_records.last).each do |eager_record|
        add_to_cache(*eager_record, element)
      end
    end

    record
  end
end

#pluck_vars(node, rel) ⇒ Object


57
58
59
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 57

def pluck_vars(node, rel)
  with_associations_tree.empty? ? super : perform_query
end

#propagate_context(query_proxy) ⇒ Object


83
84
85
86
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 83

def propagate_context(query_proxy)
  super
  query_proxy.instance_variable_set('@with_associations_tree', @with_associations_tree)
end

#with_associations(*spec) ⇒ Object


76
77
78
79
80
81
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 76

def with_associations(*spec)
  new_link.tap do |new_query_proxy|
    new_query_proxy.with_associations_tree = with_associations_tree.clone
    new_query_proxy.with_associations_tree.add_spec(spec)
  end
end

#with_associations_treeObject


88
89
90
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 88

def with_associations_tree
  @with_associations_tree ||= association_tree_class.new(model)
end

#with_associations_tree=(tree) ⇒ Object


96
97
98
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 96

def with_associations_tree=(tree)
  @with_associations_tree = tree
end