-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
findOrDefaultIfNull
issue
#701
Comments
Here's my debugging code for the function itself with how it currently operates in comments: var findOrDefaultIfNull = function (aQuery, aKey, aValue, aDefaultValue) {
// Initialize the identifiers according to the STYLEGUIDE.md
var conditions = [];
var condition = {};
// Add the search condition... regardless of state
condition[aKey] = aValue;
conditions.push(condition);
// If the current value is the same as the default value
// ... noticed the `==` instead of `===`
// reset the condition and readd it with a default of `null`
// .... **instead of the default value**
if (aValue == aDefaultValue) { // BUG: ??
condition = {};
condition[aKey] = null; // BUG: ??
conditions.push(condition);
}
console.log(conditions);
// Chain onto the existing query
aQuery.and({ $or: conditions });
}; |
I think I mixed up defaultValue and null in that function? So that if value
|
Ooooh wait. It's because we didn't set a value in mongodb if it was the
|
So would using these function identifiers clarify the usage in the code a little better?
|
Honnestly, I'd set the default value in the mongoose schema and set all null values in the db as true, then get rid of the function. That column shouldn't be nullable. But yeah, the function should be renamed and a comment added for it's use. |
Conservation of storage I think may be the goal here with using Thanks for your help in understanding this... labeling as a |
* Rename existing query filter chained condition for a DB specific use case * Create a new query filter chain specific for using defaults * Singular the search placeholder for removed items in whatever model Closes OpenUserJS#701 and post OpenUserJS#490 and OpenUserJS#700 fix
I really think this exported function is bugged… or at the very least incomplete with non-descriptive function naming...
Consider this abbreviated snippet:
… should probably just return from the function… instead it does a filter on the list with these conditions:
… and if I actually choose a default of something, say
'User'
forfindOrDefaultIfNull
, it returns this for this condition:… in other words the default is never done at all.
What, in human terms, is the function here supposed to really do? I understand it is supposed to filter but it doesn’t appear to be doing that anywhere e.g. the first line of the snippet will always set something, whether it be
false
or some other value.This issue is mainly targetted at @Zren since he did it at 7875f52 but anyone can pipe in to improve the understanding.
TIA
The text was updated successfully, but these errors were encountered: