camouflage
Advanced tools
Comparing version 0.8.7 to 0.8.8
@@ -263,17 +263,45 @@ "use strict"; | ||
var instance = this._instantiate(); | ||
_.keys(d).forEach(function(key) { | ||
return instance.fill(d); | ||
} | ||
populate() { | ||
return BaseDocument.populate(this); | ||
} | ||
fill(newValues) { | ||
var instance = this; | ||
if(newValues === null || newValues === undefined){ | ||
return this; | ||
} | ||
if(DB().isNativeId(newValues)){ | ||
this._values._id = newValues; | ||
return this; | ||
} | ||
_.keys(newValues).forEach(function(key) { | ||
var value = null; | ||
if (d[key] === null || d[key] === undefined) { | ||
value = instance.getDefault(key); | ||
if (!(key in newValues)) { | ||
value = instance._values[key]; | ||
if(value === undefined) { | ||
value = instance.getDefault(key); | ||
} | ||
} else { | ||
value = d[key]; | ||
value = newValues[key]; | ||
} | ||
// If its not in the schema, we don't care about it... right? | ||
if (key in instance._schema) { | ||
var type = instance._schema[key].type; | ||
if (type.documentClass && type.documentClass() === 'embedded') { | ||
instance._values[key] = type._fromData(value); | ||
if (type.prototype instanceof BaseDocument) { | ||
if(value === null || value === undefined){ | ||
instance._values[key] = value; | ||
} else if(instance._values[key] instanceof BaseDocument){ | ||
instance._values[key].fill(value); | ||
} else if(typeof value === 'object' && !(DB().isNativeId(value))) { | ||
instance._values[key] = type._fromData(value); | ||
} else { | ||
instance._values[key] = value; | ||
} | ||
} else if(key === '_id' || key === 'id') { | ||
instance._values[key] = DB().toNativeId(value); | ||
} else { | ||
@@ -283,14 +311,8 @@ instance._values[key] = value; | ||
} else if (key in instance) { | ||
// Handles virtual setters | ||
instance[key] = value; | ||
} | ||
}); | ||
return instance; | ||
return this; | ||
} | ||
populate() { | ||
return BaseDocument.populate(this); | ||
} | ||
// TODO : EMBEDDED | ||
@@ -382,3 +404,2 @@ // | ||
var defVal = typeof(def) === 'function' ? def() : def; | ||
this._values[schemaProp] = defVal; // TODO: Wait... should we be assigning it here? | ||
return defVal; | ||
@@ -385,0 +406,0 @@ } else if (schemaProp === '_id') { |
@@ -354,3 +354,3 @@ "use strict"; | ||
for (var i = 0; i < instancesArray.length; i++) { | ||
if (datasArray[i].hasOwnProperty('_id')) { | ||
if (datasArray[i] && datasArray[i].hasOwnProperty('_id')) { | ||
instancesArray[i].id = datasArray[i]._id; | ||
@@ -357,0 +357,0 @@ } else { |
{ | ||
"name": "camouflage", | ||
"version": "0.8.7", | ||
"version": "0.8.8", | ||
"description": "A class-based ES6 ODM for Mongo-like databases.", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -73,3 +73,3 @@ "use strict"; | ||
expect(d.mod).to.be.a('object'); | ||
expect(d.mod instanceof EmbeddedModel).to.be.true; | ||
expect(d.mod).to.be.an.instanceof(EmbeddedModel); | ||
expect(d.mod.str).to.be.equal('some data'); | ||
@@ -76,0 +76,0 @@ }).then(done, done); |
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
256451
5133