@bedrockio/model 0.12.2 → 0.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +4 -0
- package/dist/cjs/include.js +6 -0
- package/package.json +1 -1
- package/src/include.js +7 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1050,6 +1050,10 @@ await Product.findById(id).include('shop.user.^name').
|
|
|
1050
1050
|
}
|
|
1051
1051
|
```
|
|
1052
1052
|
|
|
1053
|
+
> [!WARNING] Fields that are dynamically referenced using `refPath` are unable
|
|
1054
|
+
> to resolve the schemas beforehand (ie. before query execution), therefore they
|
|
1055
|
+
> can only be populated at the top level.
|
|
1056
|
+
|
|
1053
1057
|
#### Excluded Fields
|
|
1054
1058
|
|
|
1055
1059
|
Fields can be excluded rather than included using `-`:
|
package/dist/cjs/include.js
CHANGED
|
@@ -325,6 +325,12 @@ function setNodePath(node, options) {
|
|
|
325
325
|
exclusive
|
|
326
326
|
});
|
|
327
327
|
halt = true;
|
|
328
|
+
} else if (field.refPath) {
|
|
329
|
+
// Note that dynamic references with refPath cannot "see"
|
|
330
|
+
// into a field for which they don't know the type yet (ie.
|
|
331
|
+
// before the query executes), therefore by definition
|
|
332
|
+
// dynamic references can only be populated one layer deep.
|
|
333
|
+
node[key] ||= {};
|
|
328
334
|
} else if ((0, _utils.isSchemaTypedef)(field)) {
|
|
329
335
|
node[key] = LEAF_NODE;
|
|
330
336
|
}
|
package/package.json
CHANGED
package/src/include.js
CHANGED
|
@@ -233,6 +233,7 @@ function setNodePath(node, options) {
|
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
const schema = mongoose.models[modelName]?.schema;
|
|
236
|
+
|
|
236
237
|
if (!schema) {
|
|
237
238
|
throw new Error(`Could not derive schema for ${modelName}.`);
|
|
238
239
|
}
|
|
@@ -318,6 +319,12 @@ function setNodePath(node, options) {
|
|
|
318
319
|
exclusive,
|
|
319
320
|
});
|
|
320
321
|
halt = true;
|
|
322
|
+
} else if (field.refPath) {
|
|
323
|
+
// Note that dynamic references with refPath cannot "see"
|
|
324
|
+
// into a field for which they don't know the type yet (ie.
|
|
325
|
+
// before the query executes), therefore by definition
|
|
326
|
+
// dynamic references can only be populated one layer deep.
|
|
327
|
+
node[key] ||= {};
|
|
321
328
|
} else if (isSchemaTypedef(field)) {
|
|
322
329
|
node[key] = LEAF_NODE;
|
|
323
330
|
}
|