Skip to content
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

How do I implement additional features in existing operators? #681

Closed
felipefreitasnet opened this issue Apr 19, 2018 · 2 comments
Closed
Labels
feature New feature
Milestone

Comments

@felipefreitasnet
Copy link

Hello,

I am facing a small problem with mongodb.
I use the jquery Query Builder to generate my queries in mongodb, however in my collection I have some columns of the object type, and my query needs to be able to check if the value actually exists.
For example:

{"$and":[{"custom_tags.lead.EMAILADD.value":{"$ne":""}}]}

This is the code that the querybuilder generates for me.

The problem is that there will not always be any columns, for example that part in bold does not exist. This code in mongodb returns "true"
I need my querybuilder, in the "is_not_empty" option also check if it exists, like this:

{"$and":[{"custom_tags.lead.EMAILADD.value":{"$exists": true, "$ne":""}}]}

I made this modification:

my_builder.queryBuilder({        
                ...
                mongoOperators: {
                    is_not_empty:  function(v) { return { '$exists': true, '$ne': '' }; },
                }
                ...
});

Apparently everything worked as it should, the problem is being setRulesFromMongo

my_builder.queryBuilder('setRulesFromMongo', rules);

image

How do I implement additional features in existing operators?

Thank you and sorry for my english...

@mistic100
Copy link
Owner

Right now it's impossible, the method doing the operator matching is private https://github.com/mistic100/jQuery-QueryBuilder/blob/dev/src/plugins/mongodb-support/plugin.js#L357

I'll try to find a way, you can also submit a PR if you have a nice solution.
I think iterating over all the keys until we find a valid operator is a good solution, and crash only when multiple operators are found (with the special case for "between" of course)

@mistic100 mistic100 added the feature New feature label Apr 19, 2018
@mistic100 mistic100 added this to the 2.5.2 milestone Apr 19, 2018
@felipefreitasnet
Copy link
Author

Just to be registered, I was able to solve using the is_not_null tag instead of is_not_empy, And it really makes sense.... thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

No branches or pull requests

2 participants