Skip to content

Commit

Permalink
Added schema param to mergeSchemas && bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
radixo committed Feb 9, 2017
1 parent ad29cc7 commit af5e3c1
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,15 +440,23 @@ Mongoose.prototype.modelNames.$hasSideEffects = true;
/**
* Generates a new Schema merged from others
*
* @param {Object} [schema] Object with fields that the merged Schemas does not have
* @param {Schema|Array} schemas
* @param {Object} options options like in Schema constructor
* @param {Boolean} control says when the generated schema will have control over merged schemas
* @param {Boolean} [control] says when the generated schema will have control over merged schemas
* @api public
* @return {Schema}
*/
Mongoose.prototype.mergeSchemas = function(schemas, options, control)
{
var schema = {}, dstSchema, dict = {};
Mongoose.prototype.mergeSchemas = function(schema, schemas, options, control) {
if (schema.constructor !== Object) {
control = options;
options = schemas;
schemas = schema;
schema = undefined;
}
schema = schema || {};

var dstSchema, dict = {};
var _kinds = [], _kind;
var ret; // return object

Expand All @@ -468,14 +476,15 @@ Mongoose.prototype.mergeSchemas = function(schemas, options, control)
schemas.forEach(function(obj) {
if (!(obj instanceof Schema))
throw new Error('Only Schema objects are allowed.');

if (control && !obj.options.name)
throw new Error('All SchemaS must have the name option defined.');

_kinds.push(obj.options.name);

obj.eachPath(function(p) {
// ignored fields
if (obj.options._id && p.path === obj.options.typeKey)
// ignored fields, for now (_id)
if (obj.options._id && p === '_id')
return;

p = obj.path(p);
Expand Down

0 comments on commit af5e3c1

Please sign in to comment.