flow like the river
This commit is contained in:
commit
013fe673f3
42435 changed files with 5764238 additions and 0 deletions
46
BACK_BACK/node_modules/mongoose/lib/helpers/schema/idGetter.js
generated
vendored
Executable file
46
BACK_BACK/node_modules/mongoose/lib/helpers/schema/idGetter.js
generated
vendored
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
module.exports = function addIdGetter(schema) {
|
||||
// ensure the documents receive an id getter unless disabled
|
||||
const autoIdGetter = !schema.paths['id'] &&
|
||||
schema.paths['_id'] &&
|
||||
schema.options.id;
|
||||
if (!autoIdGetter) {
|
||||
return schema;
|
||||
}
|
||||
if (schema.aliases && schema.aliases.id) {
|
||||
return schema;
|
||||
}
|
||||
schema.virtual('id').get(idGetter);
|
||||
schema.virtual('id').set(idSetter);
|
||||
|
||||
return schema;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns this documents _id cast to a string.
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function idGetter() {
|
||||
if (this._id != null) {
|
||||
return String(this._id);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {String} v the id to set
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function idSetter(v) {
|
||||
this._id = v;
|
||||
return v;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue