Skip to content

Commit

Permalink
feat(preloader): add preloadOnce to preload a relationship only once
Browse files Browse the repository at this point in the history
  • Loading branch information
zaosoula committed Dec 14, 2024
1 parent 918f473 commit 24aa495
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/orm/preloader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ export class Preloader implements PreloaderContract<LucidRow> {
return this.load(name, callback)
}

/**
* Define a relationship to preload, but only if they are not
* already preloaded
*/
preloadOnce(name: any): this {
if (!this.preloads[name]) {
return this.load(name)
}

return this
}

/**
* Toggle query debugging
*/
Expand Down

0 comments on commit 24aa495

Please sign in to comment.