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

OR and AND in a query #507

Closed
ghahramani opened this issue Apr 21, 2020 · 5 comments
Closed

OR and AND in a query #507

ghahramani opened this issue Apr 21, 2020 · 5 comments

Comments

@ghahramani
Copy link

Hi,

I tried this combination with no success findAllByWordContainsOrCommentContainsAndUser(x,x,y) it shows me an error but as soon and I changed the And to Or; it works. But a combination of OR and AND does not work together.

I thought it is supporting what Spring Data support, but it seems it has some limitation as I could easily query like that in Spring Data.

Any help with this?

@graemerocher
Copy link
Contributor

so the question is (and I ask this of Spring Data as well) does that mean:

(word.contains(x) || comment.contains(x)) && user == y

Or does it mean:

word.contains(x) || (comment.contains(x) && user == y)

For me personally that method signature is ambiguous and could mean either hence why we (and GORM which Micronaut data is based on) don't support that.

@ghahramani
Copy link
Author

Neither of them, it will be (no parentheses):

word.contains(x) || comment.contains(x) && user == y

And depends on database priority in precedence, it runs the query. For instance in SQL server, AND takes precedence over OR, so in my example, it will be like below in SQL server:

word.contains(x) || (comment.contains(x) && user == y)

@graemerocher
Copy link
Contributor

seems a slippery slow but ok, the origins of this behaviour go back to GORM actually where we restricted the number of logical branches to avoid folks abusing finders and defining ridiculously long method names which become unreadable.

@ghahramani
Copy link
Author

I think limiting to 4 conditions should be fine for most cases, or if it is possible, be configurable.
So, is there a way to support this right now? Or it will be released in future releases?

@graemerocher
Copy link
Contributor

Not currently no, but we will consider it for a future release

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

No branches or pull requests

2 participants