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

[QUESTION] Any recommendations for using DataLoader with pivot tables? #289

Open
Tracked by #297
benknight opened this issue Dec 29, 2021 · 0 comments
Open
Tracked by #297

Comments

@benknight
Copy link

benknight commented Dec 29, 2021

Pivot tables are often used in relational databases to define one-to-many relationships.

In my case I'm using Adonis.js's Lucid ORM in my GraphQL resolvers, but things get a little tricky when loading relationships that use a pivot table. For example:

const user = await context.loaders.userById.load(input.id);
const posts = await user.posts().fetch();

// Since I didn't use a loader to fetch posts, I now have to prime the cache manually:
for (let post of posts.rows) {
  context.loaders.postById.prime(post.id, post);
}

The downside to this is I lose the simplicity of only using my loaders to grab data, and I have to remember to manually priming my cache even when I might not need the data again.

@saihaj saihaj mentioned this issue Mar 11, 2022
26 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant