diff --git a/lib/connectors/memory.js b/lib/connectors/memory.js index c43e5093..386b6c14 100644 --- a/lib/connectors/memory.js +++ b/lib/connectors/memory.js @@ -348,9 +348,14 @@ Memory.prototype.all = function all(model, filter, callback) { function sorting(a, b) { for (var i = 0, l = this.length; i < l; i++) { - if (a[this[i].key] > b[this[i].key]) { + + if(a[this[i].key] === undefined && b[this[i].key] === undefined) { + return 0; + } + + if (b[this[i].key] === undefined || a[this[i].key] > b[this[i].key]) { return 1 * this[i].reverse; - } else if (a[this[i].key] < b[this[i].key]) { + } else if (a[this[i].key] === undefined || a[this[i].key] < b[this[i].key]) { return -1 * this[i].reverse; } }