elixir-mongo / elixir-mongo/mongodb_ecto

Normalized query not putting parentheses around each where statement

Open
#174 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Elixir
Stars
378
Forks
127
PR merge metrics
No merged PRs in 30d

Description

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())
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.