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

Query language support for in array and exists #5355

Closed
nwhatt opened this issue Oct 14, 2015 · 5 comments
Closed

Query language support for in array and exists #5355

nwhatt opened this issue Oct 14, 2015 · 5 comments

Comments

@nwhatt
Copy link
Contributor

nwhatt commented Oct 14, 2015

In the following where clause I want to find all of my errors that are associated with an either a specific foo or a specific bar.

Errors.find()
.where(
  {or: [ {
    foo: fooIds},{
    bar: barIds}
]})
.populate('foo')
.populate('bar')

When fooIds is empty or barIds is empty I get all of Errors that have no foo set.
One solution to this would be to design my db better, so that foo and bar are required on Error.

I was hoping there might be a better way outside of redesign - maybe a way to specify something like

  {or: [ {
    foo: fooIds, foo: {'!': null},{
    bar: barIds, bar: {'!': null}
}]})

Meaning "foo in fooIds and foo not null."

My current workaround is an if clause to dynamically construct the where clause based on whether or not my arrays are empty. Appreciate any suggestions - I may be missing a sweet query language feature.

@particlebanana
Copy link
Contributor

Interesting, we actually don't have an in key in the query language. Let's change this to a feature request and add the ability to manually specify an in key. Would you submit a PR to the roadmap for this?

This would allow the following query to work:

Errors.find({
  or: [
    { foo: { in: foodIds, '!': null } },
    { bar: { in: barIds, '!': null } }
  ]
}).exec(...)

@sailsbot
Copy link

Thanks for posting, @nwhatt. I'm a repo bot-- nice to meet you!

It has been 30 days since there have been any updates or new comments on this page. If this issue has been resolved, feel free to disregard the rest of this message. On the other hand, if you are still waiting on a patch, please:

  • review our contribution guide to make sure this submission meets our criteria (only verified bugs with documented features, please; no questions, commentary, or bug reports about undocumented features or unofficial plugins)
  • create a new issue with the latest information, including updated version details with error messages, failing tests, and a link back to the original issue. This allows GitHub to automatically create a back-reference for future visitors arriving from search engines.

Thanks so much for your help!

@devinivy
Copy link

Keeping this open until it is PRed into the roadmap.

@devinivy devinivy reopened this Nov 16, 2015
@nwhatt
Copy link
Contributor Author

nwhatt commented Nov 16, 2015

Looks like it was merged by @particlebanana
balderdashy/waterline#1195

@devinivy
Copy link

Great! Thx!

@raqem raqem transferred this issue from balderdashy/waterline May 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants