Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading across collections #77

Open
ivanyv opened this issue Mar 24, 2021 · 0 comments
Open

Loading across collections #77

ivanyv opened this issue Mar 24, 2021 · 0 comments

Comments

@ivanyv
Copy link

ivanyv commented Mar 24, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant