MCPcopy Create free account
hub / github.com/Automattic/mongoose / saveSubdocsPreSave

Function saveSubdocsPreSave

lib/plugins/saveSubdocs.js:22–40  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20// promise and force an extra microtask hop on every `save()` when there are
21// no subdocuments. kareem only awaits hooks that return a promise.
22function saveSubdocsPreSave() {
23 if (this.$isSubdocument) {
24 return;
25 }
26
27 const subdocs = this.$getAllSubdocs({ useCache: true });
28
29 if (!subdocs.length) {
30 return;
31 }
32
33 const options = this.$__.saveOptions;
34 return Promise.all(subdocs.map(subdoc => subdoc._execDocumentPreHooks('save', options, [options]))).then(() => {
35 // Invalidate subdocs cache because subdoc pre hooks can add new subdocuments
36 if (this.$__.saveOptions) {
37 this.$__.saveOptions.__subdocs = null;
38 }
39 });
40}
41
42function saveSubdocsPostSave() {
43 if (this.$isSubdocument) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected