From 795f8baf1d6e126ec3fb4cb6e3fc253db01be01d Mon Sep 17 00:00:00 2001 From: Eugene The Red Date: Fri, 25 Jun 2021 07:53:14 +0100 Subject: [PATCH] fix: when collection does not have property, should still sort --- localbase/api/actions/get.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/localbase/api/actions/get.js b/localbase/api/actions/get.js index 68aca15..9c14a6e 100644 --- a/localbase/api/actions/get.js +++ b/localbase/api/actions/get.js @@ -33,11 +33,13 @@ export default function get(options = { keys: false }) { logMessage += `, ordered by "${ orderByProperty }"` if (!options.keys) { collection.sort((a, b) => { + if (!a.hasOwnProperty(orderByProperty) || !b.hasOwnProperty(orderByProperty)) return 0 return a[orderByProperty].toString().localeCompare(b[orderByProperty].toString()) }) } else { collection.sort((a, b) => { + if (!a.hasOwnProperty(orderByProperty) || !b.hasOwnProperty(orderByProperty)) return 0 return a.data[orderByProperty].toString().localeCompare(b.data[orderByProperty].toString()) }) }