From 8a5372f3cbd75e95ab6b7e526ab097455a975f99 Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Sun, 1 Dec 2013 18:04:34 +0100 Subject: [PATCH] Detect array-specific comparison functions --- lib/model.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/model.js b/lib/model.js index 84c3e1c..318cecf 100644 --- a/lib/model.js +++ b/lib/model.js @@ -683,16 +683,15 @@ function matchQueryPart (obj, queryKey, queryValue, treatObjAsValue) { // Check if the object value is an array if (util.isArray(objValue) && !treatObjAsValue) { - // Check if we are applying a comparison function to the array itself + // Check if we are using an array-specific comparison function if (queryValue !== null && typeof queryValue === 'object' && !util.isRegExp(queryValue)) { - keys = Object.keys(queryValue); - + keys = Object.keys(queryValue); for (i = 0; i < keys.length; i += 1) { if (arrayComparisonFunctions[keys[i]]) { return matchQueryPart(obj, queryKey, queryValue, true); } } } - // Else, treat it as an array of { obj, query } where there needs to be at least one match + // If not, treat it as an array of { obj, query } where there needs to be at least one match for (i = 0; i < objValue.length; i += 1) { if (matchQueryPart({ k: objValue[i] }, 'k', queryValue)) { return true; } // k here could be any string }