Module: ActiveGraph::Node::Query::QueryProxyEagerLoading

Included in:
QueryProxy
Defined in:
lib/active_graph/node/query/query_proxy_eager_loading.rb,
lib/active_graph/node/query/query_proxy_eager_loading/association_tree.rb

Defined Under Namespace

Classes: AssociationTree, IdentityMap

Instance Method Summary collapse

Instance Method Details

#association_tree_classObject



45
46
47
# File 'lib/active_graph/node/query/query_proxy_eager_loading.rb', line 45

def association_tree_class
  AssociationTree
end

#firstObject



53
54
55
# File 'lib/active_graph/node/query/query_proxy_eager_loading.rb', line 53

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

#perform_queryObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/active_graph/node/query/query_proxy_eager_loading.rb', line 15

def perform_query
  @_cache = IdentityMap.new
  build_query
    .map do |record, eager_data|
    record = 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



11
12
13
# File 'lib/active_graph/node/query/query_proxy_eager_loading.rb', line 11

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

#propagate_context(query_proxy) ⇒ Object



36
37
38
39
# File 'lib/active_graph/node/query/query_proxy_eager_loading.rb', line 36

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

#with_associations(*spec) ⇒ Object



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

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



41
42
43
# File 'lib/active_graph/node/query/query_proxy_eager_loading.rb', line 41

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

#with_associations_tree=(tree) ⇒ Object



49
50
51
# File 'lib/active_graph/node/query/query_proxy_eager_loading.rb', line 49

def with_associations_tree=(tree)
  @with_associations_tree = tree
end