Skip to content

Loading across collections #77

@ivanyv

Description

@ivanyv

Is something like this possible?

class Types::SubcategoryType < Types::BaseObject
  def records
    BatchLoader.for(object.category_id).batch do |category_ids, loader|
      records = Record.where(category_id: category_ids).group_by(&:subcategory_id)
      loader.call(object.subcategory_id, records[object.id])
    end
  end
end

The goal is to load all records across all subcategories of a category at once. Currently the example above will return null because the batch call uses the category_id as the key, but on the loader call I'm using a subcategory_id.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions