Comparing version 1.0.4 to 1.0.5
1.0.5 / 2011-02-02 | ||
================== | ||
* Fixed; combo $push and $pushAll auto-converts into a $pushAll [brian] | ||
* Fixed; combo $pull and $pullAll auto-converts to a single $pullAll [brian] | ||
* Fixed; $pullAll now removes said members from array before save (so it acts just | ||
like pushAll) [brian] | ||
* Fixed; multiple $pulls and $pushes become a single $pullAll and $pushAll. | ||
Moreover, $pull now modifies the array before save to reflect the immediate | ||
change [brian] | ||
* Added tests for nested shortcut getters [brian] | ||
* Added tests that show that Schemas with nested Arrays don't apply defaults | ||
[brian] | ||
1.0.4 / 2011-02-02 | ||
@@ -3,0 +17,0 @@ ================== |
@@ -534,2 +534,12 @@ | ||
/** | ||
* Returns true if the Document stores the same data as doc. | ||
* @param {Document} doc to compare to | ||
* @return {Boolean} | ||
* @api public | ||
*/ | ||
Document.prototype.equals = function (doc) { | ||
return this.get('_id') === doc.get('_id'); | ||
}; | ||
/** | ||
* Wrap methods for hooks. Should be called on implemented classes (eg: Model) | ||
@@ -536,0 +546,0 @@ * Takes multiple method names as arguments. |
@@ -256,3 +256,3 @@ | ||
exports.version = '1.0.4'; | ||
exports.version = '1.0.5'; | ||
@@ -259,0 +259,0 @@ /** |
@@ -89,2 +89,34 @@ | ||
if (type._path && type.doAtomics) { | ||
['$push', '$pull'].forEach( function (opType) { | ||
var ops = type._atomics.filter( function (op) { | ||
return op[0] === opType; | ||
}) | ||
, opsAll = type._atomics.filter( function (op) { | ||
return op[0] === (opType + 'All'); | ||
}); | ||
if (ops.length > 1 || (ops.length === 1 && opsAll.length > 0)) { | ||
// If we have more than one $push (or $pull) | ||
// Or if we have at least one $push and at least one $pushAll | ||
// (or $pull and $pullAll) | ||
// Then collapse everything into one $pushAll (or $pullAll) | ||
type._atomics = type._atomics.filter( function (op) { | ||
return op[0] !== opType; | ||
}); | ||
if (opsAll.length > 0) { | ||
type._atomics = type._atomics.filter( function (op) { | ||
return op[0] !== (opType + 'All'); | ||
}); | ||
} | ||
var whatToAll = []; | ||
opsAll.forEach( function (op) { | ||
whatToAll = whatToAll.concat(op[1]); | ||
}); | ||
whatToAll = whatToAll.concat( ops.map( function (op) { | ||
return op[1]; | ||
}) ); | ||
type._atomics.push([opType + 'All', whatToAll]); | ||
} | ||
}); | ||
type._atomics.forEach( function (op) { | ||
@@ -91,0 +123,0 @@ var obj = delta[op[0]] = delta[op[0]] || {}; |
@@ -115,6 +115,3 @@ | ||
MongooseArray.prototype.push = function () { | ||
var self = this | ||
, values = Array.prototype.map.call(arguments, function(obj){ | ||
return self._cast(obj); | ||
}) | ||
var values = Array.prototype.map.call(arguments, this._cast, this) | ||
, ret = oldPush.apply(this, values); | ||
@@ -139,5 +136,3 @@ | ||
var self = this | ||
, values = Array.prototype.map.call(arguments, function (obj) { | ||
return self._cast(obj); | ||
}) | ||
, values = Array.prototype.map.call(arguments, this._cast, this) | ||
, ret = oldPush.apply(this, values); | ||
@@ -159,3 +154,3 @@ | ||
var length = this.length; | ||
this.push.apply(this, value); | ||
this.nonAtomicPush.apply(this, value); | ||
// make sure we access the casted elements | ||
@@ -214,4 +209,28 @@ this._registerAtomic(['$pushAll', this.slice(length) ]); | ||
MongooseArray.prototype.$pull = function (value) { | ||
this._registerAtomic(['$pull', value]); | ||
MongooseArray.prototype.pull = | ||
MongooseArray.prototype.$pull = function () { | ||
var values = Array.prototype.map.call(arguments, this._cast, this) | ||
, oldArr = this._parent.get(this._path) | ||
, i = oldArr.length, mem; | ||
while (i--) { | ||
mem = oldArr[i]; | ||
if (mem instanceof EmbeddedDocument) { | ||
if (values.some( function (v) { return v.equals(mem); } )) { | ||
oldArr.splice(i, 1); | ||
} | ||
} else if (~values.indexOf(mem)) oldArr.splice(i, 1); | ||
} | ||
if (1 === values.length) { | ||
if (values[0] instanceof EmbeddedDocument) { | ||
this._registerAtomic(['$pull', {_id: values[0]._id}]); | ||
} else { | ||
this._registerAtomic(['$pull', values[0]]); | ||
} | ||
} else { | ||
if (values[0] instanceof EmbeddedDocument) { | ||
this._registerAtomic(['$pullAll', values.map( function (v) { return {_id: v._id}; } )]); | ||
} else { | ||
this._registerAtomic(['$pullAll', values]); | ||
} | ||
} | ||
return this; | ||
@@ -228,2 +247,12 @@ }; | ||
if (values && values.length) | ||
var oldArr = this._parent.get(this._path) | ||
, i = oldArr.length, mem; | ||
while (i--) { | ||
mem = oldArr[i]; | ||
if (mem instanceof EmbeddedDocument) { | ||
if (values.some( function (v) { return v.equals(mem); } )) { | ||
oldArr.splice(i, 1); | ||
} | ||
} else if (~values.indexOf(mem)) oldArr.splice(i, 1); | ||
} | ||
this._registerAtomic(['$pullAll', values]); | ||
@@ -230,0 +259,0 @@ return this; |
{ | ||
"name": "mongoose" | ||
, "description": "Mongoose MongoDB ORM" | ||
, "version": "1.0.4" | ||
, "version": "1.0.5" | ||
, "author": "Guillermo Rauch <guillermo@learnboost.com>" | ||
@@ -6,0 +6,0 @@ , "keywords": ["mongodb", "mongoose", "orm", "data", "datastore", "nosql"] |
Sorry, the diff of this file is too big to display
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
1656365
28506