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

Normalized query not putting parentheses around each where statement #174

Open
diogo-ribeiro-bitmaker opened this issue May 13, 2019 · 0 comments
Labels

Comments

@diogo-ribeiro-bitmaker
Copy link

diogo-ribeiro-bitmaker commented May 13, 2019

When using multiple piped where's and if these don't contain any "and" in them, the final query ignores the "and's" that should be between the where's and therefore its parentheses, leading to a wrong query that seems good.
Eg.:

User
|> where([u], not is_nil(u.inserted_at) or u.inserted_at <= ^DateTime.utc_now())
|> where([u], is_nil(u.inserted_at) or u.inserted_at > ^DateTime.utc(now())

This query should return 0 results, but it will return all existing users.
But if you add an and to a where, like the following, it will work well:

User
|> where([u], (not is_nil(u.inserted_at) or u.inserted_at <= ^DateTime.utc_now()) and not(is_nil(u.id)))
|> where([u], is_nil(u.inserted_at) or u.inserted_at > ^DateTime.utc(now())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants