MCPcopy
hub / github.com/Automattic/mongoose / _checkContext

Function _checkContext

lib/model.js:1061–1073  ·  view source on GitHub ↗

* Make sure `this` is a model * @api private

(ctx, fnName)

Source from the content-addressed store, hash-verified

1059 */
1060
1061function _checkContext(ctx, fnName) {
1062 // Check context, because it is easy to mistakenly type
1063 // `new Model.discriminator()` and get an incomprehensible error
1064 if (ctx == null || ctx === global) {
1065 throw new MongooseError('`Model.' + fnName + '()` cannot run without a ' +
1066 'model as `this`. Make sure you are calling `MyModel.' + fnName + '()` ' +
1067 'where `MyModel` is a Mongoose model.');
1068 } else if (ctx[modelSymbol] == null) {
1069 throw new MongooseError('`Model.' + fnName + '()` cannot run without a ' +
1070 'model as `this`. Make sure you are not calling ' +
1071 '`new Model.' + fnName + '()`');
1072 }
1073}
1074
1075// Model (class) features
1076

Callers 1

model.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…