Merge pull request #5 from strongloop/memory-connector-ids
Track the greatest id to prevent records from being overriden
This commit is contained in:
commit
be15eabc36
|
@ -38,7 +38,19 @@ Memory.prototype.define = function defineModel(descr) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Memory.prototype.create = function create(model, data, callback) {
|
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;
|
data.id = id;
|
||||||
this.cache[model][id] = JSON.stringify(data);
|
this.cache[model][id] = JSON.stringify(data);
|
||||||
process.nextTick(function() {
|
process.nextTick(function() {
|
||||||
|
|
Loading…
Reference in New Issue