Skip to content

Normalized query not putting parentheses around each where statement #174

Open
@diogo-ribeiro-bitmaker

Description

@diogo-ribeiro-bitmaker

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions