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

feat(orm): add loadOnce #1052

Merged
merged 2 commits into from
Sep 25, 2024
Merged

feat(orm): add loadOnce #1052

merged 2 commits into from
Sep 25, 2024

Conversation

RomainLanz
Copy link
Member

Hey there! 👋🏻

This PR adds the loadOnce helper.

This helper is particularly useful when you're unsure whether a relation is already loaded and want to avoid unnecessary database calls if the data is already in memory.

Currently, loadOnce does not accept a callback like load does, as it's designed to avoid altering the query.

If you need to load nested relationships, you can do so like this:

await user.loadOnce('profile')
await user.profile.loadOnce('country')
// ...

@thetutlage thetutlage merged commit 96df6a6 into develop Sep 25, 2024
32 checks passed
@RomainLanz RomainLanz deleted the feat/loadOnce branch September 25, 2024 07:09
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

Successfully merging this pull request may close these issues.

2 participants