Merge pull request #5 from strongloop/memory-connector-ids

Track the greatest id to prevent records from being overriden
This commit is contained in:
Raymond Feng 2013-08-26 10:52:13 -07:00
commit be15eabc36
1 changed files with 13 additions and 1 deletions

View File

@ -38,7 +38,19 @@ Memory.prototype.define = function defineModel(descr) {
};
Memory.prototype.create = function create(model, data, callback) {
var id = data.id || this.ids[model]++;
var currentId = this.ids[model];
if(currentId === undefined) {
// First time
this.ids[model] = 1;
currentId = 1;
}
var id = data.id || currentId;
if(id > currentId) {
// If the id is passed in and the value is greater than the current id
currentId = id;
}
this.ids[model] = currentId + 1;
data.id = id;
this.cache[model][id] = JSON.stringify(data);
process.nextTick(function() {