fix sorting with undefined in memory connector

This commit is contained in:
cvette 2014-12-22 18:45:39 +01:00
parent efe4601fdb
commit a6b8ca70af
1 changed files with 7 additions and 2 deletions

View File

@ -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;
}
}