Sorry to resurrect an old thread, but I’m facing a similar issue composing this query (which is used in a larger composed query). I’m using Ecto.Query
to implement an AND
and grouped OR
query, similar to
SELECT *
FROM cities as c
WHERE
c.founded > '1900-01-01' AND c.founded < '1950-12-31'
AND ( c.population > 1000000 OR c.has_landmark = true ) #this is what I'm trying to replicate
I tried chaining or_where/2
, like so:
or_where(query, status: "Locked") |> or_where(status: "Unlocked") |> or_where(status: "Closed")
but, the composed query above are not grouped OR statements.
I tried dynamic/2
, but received the protocol Ecto.Queryable not implemented for dynamic
error).
dynamic([q], q.status == "Locked" or q.status == "Unlocked" or q.status == "Closed")
update: found the solution, all I had to do was use a keyword list.
or_where(query, [status: "Locked", status: "Unlocked", status: "Closed"])