Class: GraphQL::Models::AssociationLoadRequest
- Inherits:
-
Object
- Object
- GraphQL::Models::AssociationLoadRequest
- Defined in:
- lib/graphql/models/association_load_request.rb
Instance Attribute Summary collapse
-
#association ⇒ Object
readonly
Returns the value of attribute association.
-
#base_model ⇒ Object
readonly
Returns the value of attribute base_model.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
-
#initialize(base_model, association_name, context) ⇒ AssociationLoadRequest
constructor
A new instance of AssociationLoadRequest.
- #load ⇒ Object
- #request ⇒ Object
-
#target_class ⇒ Object
Public members specific to an association load request.
Constructor Details
#initialize(base_model, association_name, context) ⇒ AssociationLoadRequest
7 8 9 10 11 12 13 14 15 |
# File 'lib/graphql/models/association_load_request.rb', line 7 def initialize(base_model, association_name, context) @base_model = base_model @association = base_model.association(association_name) @context = context if reflection.is_a?(ActiveRecord::Reflection::ThroughReflection) raise ArgumentError, "You cannot batch-load a has_many :through association. Instead, load each association individually." end end |
Instance Attribute Details
#association ⇒ Object (readonly)
Returns the value of attribute association.
5 6 7 |
# File 'lib/graphql/models/association_load_request.rb', line 5 def association @association end |
#base_model ⇒ Object (readonly)
Returns the value of attribute base_model.
5 6 7 |
# File 'lib/graphql/models/association_load_request.rb', line 5 def base_model @base_model end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/graphql/models/association_load_request.rb', line 5 def context @context end |
Instance Method Details
#load ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/graphql/models/association_load_request.rb', line 24 def load loader.load(request).then do |result| result = result.first unless reflection.macro == :has_many Helpers.load_association_with(association, result) result end end |
#request ⇒ Object
17 18 19 20 21 22 |
# File 'lib/graphql/models/association_load_request.rb', line 17 def request AttributeLoader::Request.new( association.scope.where_values_hash, Helpers.orders_to_sql(association.scope.orders) ) end |
#target_class ⇒ Object
Public members specific to an association load request
36 37 38 39 40 41 42 |
# File 'lib/graphql/models/association_load_request.rb', line 36 def target_class if reflection.polymorphic? base_model.send(reflection.foreign_type).constantize else reflection.klass end end |