module Neo4j::ActiveNode::Query::QueryProxyEagerLoading
Public Instance Methods
each(node = true, rel = nil, &block)
click to toggle source
Calls superclass method
# File lib/neo4j/active_node/query/query_proxy_eager_loading.rb 5 def each(node = true, rel = nil, &block) 6 return super if with_associations_spec.size.zero? 7 8 query_from_association_spec.pluck(identity, "[#{with_associations_return_clause}]").map do |record, eager_data| 9 eager_data.each_with_index do |eager_records, index| 10 record.association_proxy(with_associations_spec[index]).cache_result(eager_records) 11 end 12 13 block.call(record) 14 end 15 end
with_associations(*spec)
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_eager_loading.rb 21 def with_associations(*spec) 22 invalid_association_names = spec.reject do |association_name| 23 model.associations[association_name] 24 end 25 26 if invalid_association_names.size > 0 27 fail "Invalid associations: #{invalid_association_names.join(', ')}" 28 end 29 30 new_link.tap do |new_query_proxy| 31 new_spec = new_query_proxy.with_associations_spec + spec 32 new_query_proxy.with_associations_spec.replace(new_spec) 33 end 34 end
with_associations_spec()
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_eager_loading.rb 17 def with_associations_spec 18 @with_associations_spec ||= [] 19 end
Private Instance Methods
query_from_association_spec()
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_eager_loading.rb 42 def query_from_association_spec 43 previous_with_variables = [] 44 with_associations_spec.inject(query_as(identity).with(identity)) do |query, association_name| 45 with_association_query_part(query, association_name, previous_with_variables).tap do 46 previous_with_variables << association_name 47 end 48 end.return(identity) 49 end
with_association_query_part(base_query, association_name, previous_with_variables)
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_eager_loading.rb 51 def with_association_query_part(base_query, association_name, previous_with_variables) 52 association = model.associations[association_name] 53 54 base_query.optional_match("(#{identity})#{association.arrow_cypher}(#{association_name})") 55 .where(association.target_where_clause) 56 .with(identity, "collect(#{association_name}) AS #{association_name}_collection", *with_associations_return_clause(previous_with_variables)) 57 end
with_associations_return_clause(variables = with_associations_spec)
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_eager_loading.rb 38 def with_associations_return_clause(variables = with_associations_spec) 39 variables.map { |n| "#{n}_collection" }.join(',') 40 end