Comparing version 1.1.18 to 1.1.19
1.1.19 / 2011-03-31 | ||
=================== | ||
* Fixed; no longer using $set on paths to an unexisting fields | ||
1.1.18 / 2011-03-30 | ||
@@ -3,0 +8,0 @@ =================== |
@@ -239,3 +239,4 @@ | ||
Connection.prototype.close = function (callback) { | ||
var self = this; | ||
var self = this | ||
, callback = callback || function(){}; | ||
@@ -251,6 +252,6 @@ switch (this.readyState){ | ||
if (err){ | ||
if (callback) callback(err); | ||
callback(err); | ||
} else { | ||
self.onClose(); | ||
if (callback) callback(null); | ||
callback(null); | ||
} | ||
@@ -257,0 +258,0 @@ }); |
@@ -190,40 +190,65 @@ | ||
Document.prototype.set = function (path, val) { | ||
if (typeof path != 'string'){ | ||
var prefix = val ? val + '.' : ''; | ||
for (var i in path){ | ||
if (!(this.schema.path(prefix + i) instanceof MixedSchema) | ||
&& 'undefined' !== typeof path[i] | ||
&& path[i] !== null | ||
&& path[i].constructor == Object) { | ||
this.set(path[i], prefix + i); | ||
} else if ('undefined' !== typeof path[i]) { | ||
this.set(prefix + i, path[i]); | ||
if (typeof path != 'string') { | ||
var prefix = val | ||
? val + '.' | ||
: ''; | ||
var keys = Object.keys(path); | ||
var i = keys.length; | ||
var key; | ||
while (i--) { | ||
key = keys[i]; | ||
if (!(this.schema.path(prefix + key) instanceof MixedSchema) | ||
&& undefined !== path[key] | ||
&& null !== path[key] | ||
&& Object == path[key].constructor) { | ||
this.set(path[key], prefix + key); | ||
} else if (undefined !== path[key]) { | ||
this.set(prefix + key, path[key]); | ||
} | ||
} | ||
} else { | ||
// TODO: do actual checking to see if the value changed | ||
var schema = this.schema.path(path) | ||
, parts = path.split('.') | ||
, obj = this.doc | ||
, self = this; | ||
if (this.schema.pathType(path) === 'virtual') { | ||
schema = this.schema.virtualpath(path); | ||
schema.applySetters(val, this); | ||
return this; | ||
return this; | ||
} | ||
// TODO: do actual checking to see if the value changed | ||
var schema = this.schema.path(path) | ||
, parts = path.split('.') | ||
, obj = this.doc | ||
, self = this; | ||
if (this.schema.pathType(path) === 'virtual') { | ||
schema = this.schema.virtualpath(path); | ||
schema.applySetters(val, this); | ||
return this; | ||
} | ||
// When using the $set operator the path to the field must already exist. | ||
// Else mongodb throws: "LEFT_SUBFIELD only supports Object" | ||
var markedModified; | ||
if (parts.length > 1) { | ||
for (var i = 0, len = parts.length - 1; i <= len; ++i) { | ||
if (null === this.get(parts[i])) { | ||
this.activePaths.modify(parts[i]); | ||
markedModified = true; | ||
break; | ||
} | ||
} | ||
} | ||
if (!markedModified) | ||
this.activePaths.modify(path); | ||
if ( (!schema || val === null || val === undefined) || | ||
this.try(function(){ | ||
val = schema.applySetters(schema.cast(val, self), self); | ||
}) | ||
){ | ||
for (var i = 0, l = parts.length; i < l; i++){ | ||
if (i + 1 == l) | ||
obj[parts[i]] = val; | ||
else { | ||
obj = obj[parts[i]] || (obj[parts[i]] = {}); | ||
} | ||
if ( (!schema || null === val || undefined === val) || | ||
this.try(function(){ | ||
val = schema.applySetters(schema.cast(val, self), self); | ||
}) | ||
){ | ||
for (var i = 0, l = parts.length; i < l; i++) { | ||
if (i + 1 == l) { | ||
obj[parts[i]] = val; | ||
} else { | ||
obj = obj[parts[i]] || (obj[parts[i]] = {}); | ||
} | ||
@@ -230,0 +255,0 @@ } |
@@ -284,3 +284,3 @@ | ||
exports.version = '1.1.18'; | ||
exports.version = '1.1.19'; | ||
@@ -287,0 +287,0 @@ /** |
@@ -82,3 +82,5 @@ | ||
var dirty = this.activePaths.map('modify', function (path) { | ||
return { path: path, value: self.getValue(path), schema: self.schema.path(path) }; | ||
return { path: path | ||
, value: self.getValue(path) | ||
, schema: self.schema.path(path) }; | ||
}); | ||
@@ -85,0 +87,0 @@ |
{ | ||
"name": "mongoose" | ||
, "description": "Mongoose MongoDB ORM" | ||
, "version": "1.1.18" | ||
, "version": "1.1.19" | ||
, "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
26191
3077366
211