From fb66f3afd67070a8512ecbb404e6ea69ecb275c3 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Mon, 7 Oct 2019 14:29:59 -0400 Subject: [PATCH] fix: use options constructor class for all schematypes Fix #8012 --- lib/options/SchemaObjectIdOptions.js | 30 ++++++++++++++++++++++++++++ lib/schema/objectid.js | 4 +++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 lib/options/SchemaObjectIdOptions.js diff --git a/lib/options/SchemaObjectIdOptions.js b/lib/options/SchemaObjectIdOptions.js new file mode 100644 index 00000000000..67ecc8a863d --- /dev/null +++ b/lib/options/SchemaObjectIdOptions.js @@ -0,0 +1,30 @@ +'use strict'; + +const SchemaTypeOptions = require('./SchemaTypeOptions'); + +class SchemaObjectIdOptions extends SchemaTypeOptions {} + +const opts = { + enumerable: true, + configurable: true, + writable: true, + value: null +}; + +/** + * If truthy, uses Mongoose's default built-in ObjectId path. + * + * @api public + * @property auto + * @memberOf SchemaObjectIdOptions + * @type Boolean + * @instance + */ + +Object.defineProperty(SchemaObjectIdOptions.prototype, 'auto', opts); + +/*! + * ignore + */ + +module.exports = SchemaObjectIdOptions; \ No newline at end of file diff --git a/lib/schema/objectid.js b/lib/schema/objectid.js index 2a07c118d2a..ae20493159b 100644 --- a/lib/schema/objectid.js +++ b/lib/schema/objectid.js @@ -4,8 +4,9 @@ 'use strict'; -const castObjectId = require('../cast/objectid'); +const SchemaObjectIdOptions = require('../options/SchemaObjectIdOptions'); const SchemaType = require('../schematype'); +const castObjectId = require('../cast/objectid'); const oid = require('../types/objectid'); const utils = require('../utils'); @@ -49,6 +50,7 @@ ObjectId.schemaName = 'ObjectId'; */ ObjectId.prototype = Object.create(SchemaType.prototype); ObjectId.prototype.constructor = ObjectId; +ObjectId.prototype.OptionsConstructor = SchemaObjectIdOptions; /** * Attaches a getter for all ObjectId instances