From bede7ab499fa53f5e537f1df501a7c55f8a342c7 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Thu, 22 Aug 2013 16:44:02 -0700 Subject: [PATCH] Track the greatest id to prevent records from being overriden --- lib/connectors/memory.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/connectors/memory.js b/lib/connectors/memory.js index 7174f396..83d8eb08 100644 --- a/lib/connectors/memory.js +++ b/lib/connectors/memory.js @@ -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() {