Comparing version 2.0.1 to 2.0.2
2.0.2 / 2011-08-25 | ||
================== | ||
* Fixed; Maintain query option key order (fixes 'bad hint' error from compound query hints) | ||
2.0.1 / 2011-08-25 | ||
================== | ||
* Fixed; do not over-write the doc when no valide props exist in Model.update | ||
* Fixed; do not over-write the doc when no valide props exist in Model.update (#473) | ||
@@ -8,0 +12,0 @@ 2.0.0 / 2011-08-24 |
@@ -759,3 +759,3 @@ | ||
if (ref) return this._doc; | ||
return clone(this._doc, true); | ||
return clone(this._doc, { minimize: true }); | ||
}; | ||
@@ -762,0 +762,0 @@ |
@@ -287,3 +287,3 @@ | ||
exports.version = '2.0.1'; | ||
exports.version = '2.0.2'; | ||
@@ -290,0 +290,0 @@ /** |
@@ -254,3 +254,4 @@ /** | ||
Query.prototype._optionsForExec = function (model) { | ||
var options = utils.clone(this.options); | ||
var options = utils.clone(this.options, { retainKeyOrder: true }); | ||
delete options.populate; | ||
if (! ('safe' in options)) options.safe = model.options.safe; | ||
@@ -257,0 +258,0 @@ return options; |
@@ -200,3 +200,3 @@ /** | ||
* @param {Object} object to clone | ||
* @param {Boolean} shouldMinimizeData | ||
* @param {Object} options - minimize , retainKeyOrder | ||
* @return {Object} cloned object | ||
@@ -206,8 +206,8 @@ * @api private | ||
var clone = exports.clone = function (obj, shouldMinimizeData) { | ||
var clone = exports.clone = function clone (obj, options) { | ||
if (obj === undefined || obj === null) | ||
return obj | ||
return obj; | ||
if (Array.isArray(obj)) | ||
return cloneArray(obj, shouldMinimizeData); | ||
return cloneArray(obj, options); | ||
@@ -218,3 +218,3 @@ if (obj.toObject) | ||
if (obj.constructor == Object) | ||
return cloneObject(obj, shouldMinimizeData); | ||
return cloneObject(obj, options); | ||
@@ -234,21 +234,39 @@ if (obj.constructor == Date || obj.constructor == Function) | ||
function cloneObject (obj, shouldMinimizeData) { | ||
var ret = {} | ||
function cloneObject (obj, options) { | ||
var retainKeyOrder = options && options.retainKeyOrder | ||
, minimize = options && options.minimize | ||
, ret = {} | ||
, hasKeys | ||
, keys | ||
, val | ||
, hasKeys | ||
, keys = Object.keys(obj) | ||
, i = keys.length | ||
, key | ||
, k | ||
, i | ||
while (i--) { | ||
key = keys[i]; | ||
val = clone(obj[key], shouldMinimizeData); | ||
if (retainKeyOrder) { | ||
for (k in obj) { | ||
val = clone(obj[k], options); | ||
if (!shouldMinimizeData || ('undefined' !== typeof val)) { | ||
if (!hasKeys) hasKeys = true; | ||
ret[key] = val; | ||
if (!minimize || ('undefined' !== typeof val)) { | ||
hasKeys || (hasKeys = true); | ||
ret[k] = val; | ||
} | ||
} | ||
} else { | ||
// faster | ||
keys = Object.keys(obj); | ||
i = keys.length; | ||
while (i--) { | ||
k = keys[i]; | ||
val = clone(obj[k], options); | ||
if (!minimize || ('undefined' !== typeof val)) { | ||
if (!hasKeys) hasKeys = true; | ||
ret[k] = val; | ||
} | ||
} | ||
} | ||
return shouldMinimizeData | ||
return minimize | ||
? hasKeys && ret | ||
@@ -258,9 +276,10 @@ : ret; | ||
function cloneArray (arr, shouldMinimizeData) { | ||
function cloneArray (arr, options) { | ||
var ret = []; | ||
for (var i = 0, l = arr.length; i < l; i++) | ||
ret.push(clone(arr[i], shouldMinimizeData)); | ||
ret.push(clone(arr[i], options)); | ||
return ret; | ||
}; | ||
/** | ||
@@ -267,0 +286,0 @@ * Copies and merges options with defaults. |
{ | ||
"name": "mongoose" | ||
, "description": "Mongoose MongoDB ORM" | ||
, "version": "2.0.1" | ||
, "version": "2.0.2" | ||
, "author": "Guillermo Rauch <guillermo@learnboost.com>" | ||
@@ -6,0 +6,0 @@ , "keywords": ["mongodb", "mongoose", "orm", "data", "datastore", "nosql"] |
@@ -526,2 +526,3 @@ | ||
title: 'Woot' | ||
, _creator: user1._id | ||
, comments: [ | ||
@@ -536,9 +537,11 @@ { _creator: user1._id, content: 'Woot woot' } | ||
.findById(post._id) | ||
.populate('_creator') | ||
.populate('comments._creator') | ||
.run(function (err, post) { | ||
db.close(); | ||
should.strictEqual(err, null); | ||
post._creator.name.should.equal('User 1'); | ||
post.comments[0]._creator.name.should.equal('User 1'); | ||
post.comments[1]._creator.name.should.equal('User 2'); | ||
db.close(); | ||
}); | ||
@@ -545,0 +548,0 @@ }); |
@@ -732,2 +732,15 @@ | ||
'optionsForExecute should retain key order': function () { | ||
// this is important for query hints | ||
var hint = { x: 1, y: 1, z: 1 }; | ||
var a = JSON.stringify({ hint: hint, safe: true}); | ||
var q = new Query; | ||
q.hint(hint); | ||
var options = q._optionsForExec({ options: { safe: true } }); | ||
a.should.equal(JSON.stringify(options)); | ||
}, | ||
// Advanced Query options | ||
@@ -734,0 +747,0 @@ |
727511
16078