Class: Graphiti::ActiveGraph::Scoping::AssociationEagerLoad
- Inherits:
-
Scoping::Base
- Object
- Scoping::Base
- Graphiti::ActiveGraph::Scoping::AssociationEagerLoad
- Defined in:
- lib/graphiti/active_graph/scoping/association_eager_load.rb
Instance Method Summary collapse
- #apply_standard_scope ⇒ Object
- #custom_scope ⇒ Object
- #eagerload_association(key, ids) ⇒ Object
- #eagerload_associations? ⇒ Boolean
- #nil_or_empty(key) ⇒ Object
Instance Method Details
#apply_standard_scope ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/graphiti/active_graph/scoping/association_eager_load.rb', line 8 def apply_standard_scope return @scope unless eagerload_associations? if (ids = @scope.collect(&:id)).present? @opts[:query_obj].include_hash.each_key do |key| eagerload_association(key, ids) end end @scope end |
#custom_scope ⇒ Object
4 5 6 |
# File 'lib/graphiti/active_graph/scoping/association_eager_load.rb', line 4 def custom_scope nil end |
#eagerload_association(key, ids) ⇒ Object
23 24 25 26 27 |
# File 'lib/graphiti/active_graph/scoping/association_eager_load.rb', line 23 def eagerload_association(key, ids) return unless @resource.model.eagerload_association?(key) nodes = @resource.model.association_nodes(key, ids, @resource.context.send(:association_filter_params)) @scope.each { |node| node.send("#{key}=", nodes[node.id] || nil_or_empty(key)) } end |
#eagerload_associations? ⇒ Boolean
18 19 20 21 |
# File 'lib/graphiti/active_graph/scoping/association_eager_load.rb', line 18 def eagerload_associations? @opts[:query_obj].include_hash.present? && @resource.model.include?(ActiveGraph::Node) && @resource.model.associations_to_eagerload.present? end |
#nil_or_empty(key) ⇒ Object
29 30 31 |
# File 'lib/graphiti/active_graph/scoping/association_eager_load.rb', line 29 def nil_or_empty(key) @resource.class.config[:sideloads][key].type == :has_one ? nil : [] end |