class ActiveForce::Association::AbstractProjectionBuilder

Attributes

association[R]
parent_association_field[R]
query_fields[R]

Public Class Methods

new(association, parent_association_field = nil, query_fields = nil) click to toggle source
# File lib/active_force/association/eager_load_projection_builder.rb, line 35
def initialize(association, parent_association_field = nil, query_fields = nil)
  @association = association
  @parent_association_field = parent_association_field
  @query_fields = query_fields
end

Public Instance Methods

apply_association_scope(query) click to toggle source
# File lib/active_force/association/eager_load_projection_builder.rb, line 45
def apply_association_scope(query)
  return query unless association.scoped?
  raise InvalidEagerLoadAssociation, "Cannot use scopes that expect arguments: #{association.relation_name}" if association.scoped_as.arity.positive?

  query.instance_exec(&association.scoped_as)
end
projections() click to toggle source
# File lib/active_force/association/eager_load_projection_builder.rb, line 41
def projections
  raise "Must define #{self.class.name}#projections"
end
query_with_association_fields() click to toggle source

Use ActiveForce::Query to build a subquery for the SFDC relationship name. Per SFDC convention, the name needs to be pluralized

# File lib/active_force/association/eager_load_projection_builder.rb, line 56
def query_with_association_fields
  relationship_name = association.sfdc_association_field
  selected_fields = query_fields || association.relation_model.fields
  query = ActiveQuery.new(association.relation_model, relationship_name).select(*selected_fields)
  apply_association_scope(query)
end