Skip to content

Commit

Permalink
fix: use options constructor class for all schematypes
Browse files Browse the repository at this point in the history
Fix #8012
  • Loading branch information
vkarpov15 committed Oct 7, 2019
1 parent d5e0c73 commit fb66f3a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
30 changes: 30 additions & 0 deletions lib/options/SchemaObjectIdOptions.js
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 3 additions & 1 deletion lib/schema/objectid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fb66f3a

Please sign in to comment.