Module: Neo4j::ActiveNode::Query::QueryProxyEagerLoading
- Included in:
- QueryProxy
- Defined in:
- lib/neo4j/active_node/query/query_proxy_eager_loading.rb
Instance Method Summary collapse
- #each(node = true, rel = nil, &block) ⇒ Object
- #with_associations(*spec) ⇒ Object
- #with_associations_spec ⇒ Object
Instance Method Details
#each(node = true, rel = nil, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 5 def each(node = true, rel = nil, &block) return super if with_associations_spec.size.zero? query_from_association_spec.pluck(identity, "[#{with_associations_return_clause}]").map do |record, eager_data| eager_data.each_with_index do |eager_records, index| record.association_proxy(with_associations_spec[index]).cache_result(eager_records) end block.call(record) end end |
#with_associations(*spec) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 21 def with_associations(*spec) invalid_association_names = spec.reject do |association_name| model.associations[association_name] end if invalid_association_names.size > 0 fail "Invalid associations: #{invalid_association_names.join(', ')}" end new_link.tap do |new_query_proxy| new_spec = new_query_proxy.with_associations_spec + spec new_query_proxy.with_associations_spec.replace(new_spec) end end |
#with_associations_spec ⇒ Object
17 18 19 |
# File 'lib/neo4j/active_node/query/query_proxy_eager_loading.rb', line 17 def with_associations_spec @with_associations_spec ||= [] end |