Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: fix(document): allow validation of moddelless documents on node side #8289

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/index.js
Expand Up @@ -23,6 +23,7 @@ const STATES = require('./connectionstate');
const Types = require('./types');
const Query = require('./query');
const Model = require('./model');
const BrowserDocument = require('./browserDocument');
const Document = require('./document');
const applyPlugins = require('./helpers/schema/applyPlugins');
const get = require('./helpers/get');
Expand Down Expand Up @@ -396,6 +397,25 @@ Mongoose.prototype.pluralize = function(fn) {
return _mongoose._pluralize;
};


Mongoose.prototype.ephemodel = function(schema, skipInit) {
let ephemodel = function Ephemodel(doc, fields, skipId) {
if (doc instanceof Schema) {
throw new TypeError('Argument to `Ephemodel` must be a POJO, ' +
'**not** a schema. Make sure you\'re calling `mongoose.ephemodel()`, not ' +
'`mongoose.Ephemodel()`.');
}
BrowserDocument.call(this, doc, this.schema, fields, skipId, skipInit);
};
ephemodel.__proto__ = BrowserDocument;

ephemodel.prototype = Object.create(BrowserDocument.prototype);
ephemodel.prototype.constructor = ephemodel;

ephemodel.prototype.schema = schema;
return ephemodel;
}

/**
* Defines a model or retrieves it.
*
Expand Down