Class: ActiveForce::Association::AbstractProjectionBuilder
- Inherits:
-
Object
- Object
- ActiveForce::Association::AbstractProjectionBuilder
- Defined in:
- lib/active_force/association/eager_load_projection_builder.rb
Direct Known Subclasses
BelongsToAssociationProjectionBuilder, HasManyAssociationProjectionBuilder, HasOneAssociationProjectionBuilder
Instance Attribute Summary collapse
-
#association ⇒ Object
readonly
Returns the value of attribute association.
-
#parent_association_field ⇒ Object
readonly
Returns the value of attribute parent_association_field.
-
#query_fields ⇒ Object
readonly
Returns the value of attribute query_fields.
Instance Method Summary collapse
- #apply_association_scope(query) ⇒ Object
-
#initialize(association, parent_association_field = nil, query_fields = nil) ⇒ AbstractProjectionBuilder
constructor
A new instance of AbstractProjectionBuilder.
- #projections ⇒ Object
-
#query_with_association_fields ⇒ Object
Use ActiveForce::Query to build a subquery for the SFDC relationship name.
Constructor Details
#initialize(association, parent_association_field = nil, query_fields = nil) ⇒ AbstractProjectionBuilder
Returns a new instance of AbstractProjectionBuilder.
35 36 37 38 39 |
# 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 |
Instance Attribute Details
#association ⇒ Object (readonly)
Returns the value of attribute association.
33 34 35 |
# File 'lib/active_force/association/eager_load_projection_builder.rb', line 33 def association @association end |
#parent_association_field ⇒ Object (readonly)
Returns the value of attribute parent_association_field.
33 34 35 |
# File 'lib/active_force/association/eager_load_projection_builder.rb', line 33 def parent_association_field @parent_association_field end |
#query_fields ⇒ Object (readonly)
Returns the value of attribute query_fields.
33 34 35 |
# File 'lib/active_force/association/eager_load_projection_builder.rb', line 33 def query_fields @query_fields end |
Instance Method Details
#apply_association_scope(query) ⇒ Object
45 46 47 48 49 50 |
# 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 ⇒ Object
41 42 43 |
# 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 ⇒ Object
Use ActiveForce::Query to build a subquery for the SFDC relationship name. Per SFDC convention, the name needs to be pluralized
56 57 58 59 60 61 |
# 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 |