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:
parent
4940187663
commit
0a3e642c9e
|
@ -229,9 +229,26 @@ Memory.prototype.count = function count(model, callback, where) {
|
|||
};
|
||||
|
||||
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;
|
||||
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 () {
|
||||
|
|
Loading…
Reference in New Issue