@bedrockio/model 0.2.15 → 0.2.17

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.
@@ -22,12 +22,27 @@ function transformField(obj, field, options) {
22
22
  if (Array.isArray(obj)) {
23
23
  for (let el of obj) {
24
24
  transformField(el, field, options);
25
- // Delete ids in array elements.
26
- delete el.id;
27
25
  }
28
26
  } else if ((0, _lodash.isPlainObject)(obj)) {
29
27
  for (let [key, val] of Object.entries(obj)) {
30
28
  if (!isAllowedField(key, field, options)) {
29
+ // Although the "id" field is automatically added for most
30
+ // documents, this doesn't appear to be the case for mongoose
31
+ // schemas with a "type" field that is an array. For example:
32
+ //
33
+ // "type": [
34
+ // {
35
+ // "name": "String"
36
+ // }
37
+ // ]
38
+ //
39
+ // This may be a mongoose bug.
40
+ // The "type": "Array" extended syntax wraps this behavior, so
41
+ // to keep consistency with other array field declaration types,
42
+ // force the "id" field to be set here.
43
+ if (key === '_id') {
44
+ obj.id = val.toString();
45
+ }
31
46
  delete obj[key];
32
47
  } else {
33
48
  transformField(val, (0, _utils.getInnerField)(field, key), options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/model",
3
- "version": "0.2.15",
3
+ "version": "0.2.17",
4
4
  "description": "Bedrock utilities for model creation.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -20,12 +20,27 @@ function transformField(obj, field, options) {
20
20
  if (Array.isArray(obj)) {
21
21
  for (let el of obj) {
22
22
  transformField(el, field, options);
23
- // Delete ids in array elements.
24
- delete el.id;
25
23
  }
26
24
  } else if (isPlainObject(obj)) {
27
25
  for (let [key, val] of Object.entries(obj)) {
28
26
  if (!isAllowedField(key, field, options)) {
27
+ // Although the "id" field is automatically added for most
28
+ // documents, this doesn't appear to be the case for mongoose
29
+ // schemas with a "type" field that is an array. For example:
30
+ //
31
+ // "type": [
32
+ // {
33
+ // "name": "String"
34
+ // }
35
+ // ]
36
+ //
37
+ // This may be a mongoose bug.
38
+ // The "type": "Array" extended syntax wraps this behavior, so
39
+ // to keep consistency with other array field declaration types,
40
+ // force the "id" field to be set here.
41
+ if (key === '_id') {
42
+ obj.id = val.toString();
43
+ }
29
44
  delete obj[key];
30
45
  } else {
31
46
  transformField(val, getInnerField(field, key), options);