Detect array-specific comparison functions

pull/2/head
Louis Chatriot 11 years ago
parent bbbc18137c
commit 8a5372f3cb
  1. 5
      lib/model.js

@ -683,16 +683,15 @@ function matchQueryPart (obj, queryKey, queryValue, treatObjAsValue) {
// Check if the object value is an array // Check if the object value is an array
if (util.isArray(objValue) && !treatObjAsValue) { 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)) { 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) { for (i = 0; i < keys.length; i += 1) {
if (arrayComparisonFunctions[keys[i]]) { return matchQueryPart(obj, queryKey, queryValue, true); } 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) { for (i = 0; i < objValue.length; i += 1) {
if (matchQueryPart({ k: objValue[i] }, 'k', queryValue)) { return true; } // k here could be any string if (matchQueryPart({ k: objValue[i] }, 'k', queryValue)) { return true; } // k here could be any string
} }

Loading…
Cancel
Save