Add support for lazy loading relations #190
mammadataei
started this conversation in
Ideas
Replies: 1 comment 4 replies
-
|
Hey, @mammadataei. Thank you for suggesting this. Internally, all relationships are resolved by pointers to primary keys. You are not missing on performance when using relationships. I think I'd like to understand your use case a little better. So your intention is to implement an API that would return primary key pointers when querying data? I think you can implement that in your mock API directly. The output from rest.get('/album/:id', (req, res, ctx) => {
const album = db.album.findFirst({
where: { id: { equals: req.params.id } }
})
// "album.songs" will contain full values for each song object.
// Let's reduce them to just pointers.
const lazyAlbum = album.songs.map(song => ({ id: song.id }))
return res(ctx.json({ album: lazyAlbum }))
})I can see how this may make sense if your application expects lazy data structures and evolves them on its own. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I think it would be great if the relations support lazy loading and return the primary key of the target model instead of its data.
It will be useful while working with complex APIs that do not eager-load all the relations to generate smaller payloads.
Beta Was this translation helpful? Give feedback.
All reactions