Comparing version 1.3.2 to 1.3.3
@@ -137,27 +137,50 @@ /// <reference path="../nodelib/node.js"/> | ||
Model.prototype.insert = Model.prototype.create = function (object, callback) { | ||
/// <signature> | ||
/// <summary>Inserts the given object into the database</summary> | ||
/// <param name="object" type="Object">The properties to set on the newly created object</param> | ||
/// <param name="callback" type="Function"></param> | ||
/// <param name="callback" type="Function">A function to be called once the object has been created</param> | ||
/// </signature> | ||
/// <signature> | ||
/// <summary>Inserts the given object into the database</summary> | ||
/// <param name="object" type="Array" elementType="Object">An array of objects representing the properties to set on the newly created objects</param> | ||
/// <param name="callback" type="Function">A function to be called once the objects have been created</param> | ||
/// </signature> | ||
var $ = this; | ||
var doInsert = function(err) { | ||
if(err) return callback(err); | ||
if(!Array.isArray(object)) object = [object]; | ||
var created = []; | ||
var next = function(err, instance) { | ||
if(err) return callback(err, created); | ||
if(instance) created.push(instance); | ||
if(object.length === 0) { | ||
$.setupIndexes(); | ||
return callback(null, created); | ||
} | ||
var toInsert = object.shift(); | ||
doHook(toInsert); | ||
} | ||
var doInsert = function(err, object, next) { | ||
if(err) return next(err); | ||
var validation = validate($.options.schema, object); | ||
if (!validation.passed) return callback(validation.toError()); | ||
if (!validation.passed) return next(validation.toError()); | ||
var instance = $.wrap.call($, object, true); | ||
instance.save(callback); | ||
$.setupIndexes(); | ||
instance.save(next); | ||
}; | ||
if (this.options.hooks.beforeCreate) { | ||
var doHook = function(object) { | ||
if (this.options.hooks.beforeCreate) { | ||
if (this.options.hooks.beforeCreate.length === 0) this.options.hooks.beforeCreate.call(object); | ||
else return this.options.hooks.beforeCreate.call(object, doInsert); | ||
} | ||
else return this.options.hooks.beforeCreate.call(object, doInsert); | ||
} | ||
}; | ||
doInsert(); | ||
next(); | ||
}; | ||
@@ -164,0 +187,0 @@ |
{ | ||
"name": "iridium", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"author": "Benjamin Pannell <admin@sierrasoftworks.com>", | ||
@@ -5,0 +5,0 @@ "description": "A custom lightweight ORM for MongoDB designed for power-users", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
293351
58
5652