Class: Gitlab::Graphql::Loaders::BatchModelLoader
- Inherits:
-
Object
- Object
- Gitlab::Graphql::Loaders::BatchModelLoader
- Defined in:
- lib/gitlab/graphql/loaders/batch_model_loader.rb
Instance Attribute Summary collapse
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
-
#model_id ⇒ Object
readonly
Returns the value of attribute model_id.
Instance Method Summary collapse
-
#find ⇒ Object
rubocop: disable CodeReuse/ActiveRecord.
-
#initialize(model_class, model_id) ⇒ BatchModelLoader
constructor
A new instance of BatchModelLoader.
Constructor Details
#initialize(model_class, model_id) ⇒ BatchModelLoader
Returns a new instance of BatchModelLoader.
9 10 11 12 |
# File 'lib/gitlab/graphql/loaders/batch_model_loader.rb', line 9 def initialize(model_class, model_id) @model_class = model_class @model_id = model_id end |
Instance Attribute Details
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
7 8 9 |
# File 'lib/gitlab/graphql/loaders/batch_model_loader.rb', line 7 def model_class @model_class end |
#model_id ⇒ Object (readonly)
Returns the value of attribute model_id.
7 8 9 |
# File 'lib/gitlab/graphql/loaders/batch_model_loader.rb', line 7 def model_id @model_id end |
Instance Method Details
#find ⇒ Object
rubocop: disable CodeReuse/ActiveRecord
15 16 17 18 19 20 21 22 |
# File 'lib/gitlab/graphql/loaders/batch_model_loader.rb', line 15 def find BatchLoader::GraphQL.for(model_id.to_i).batch(key: model_class) do |ids, loader, args| model = args[:key] results = model.where(id: ids) results.each { |record| loader.call(record.id, record) } end end |