Fix memory adapter updateAttributes issue.

Callback with an error if an id was not provided or if a model was not
found by that id.
This commit is contained in:
Ritchie Martori 2013-06-21 14:56:21 -07:00
parent 4940187663
commit 0a3e642c9e
1 changed files with 19 additions and 2 deletions

View File

@ -229,9 +229,26 @@ Memory.prototype.count = function count(model, callback, where) {
}; };
Memory.prototype.updateAttributes = function updateAttributes(model, id, data, cb) { Memory.prototype.updateAttributes = function updateAttributes(model, id, data, cb) {
if(!id) {
var err = new Error('You must provide an id when updating attributes!');
if(cb) {
return cb(err);
} else {
throw err;
}
}
data.id = id; data.id = id;
var base = JSON.parse(this.cache[model][id]);
this.save(model, merge(base, data), cb); var cachedModels = this.cache[model];
var modelAsString = cachedModels && this.cache[model][id];
var modelData = modelAsString && JSON.parse(modelAsString);
if(modelData) {
this.save(model, merge(base, data), cb);
} else {
cb(new Error('Could not update attributes. Object with id ' + id + ' does not exist!'));
}
}; };
Memory.prototype.transaction = function () { Memory.prototype.transaction = function () {