Can one do a disjunctive search in Ecto – find records satisfying THIS or THAT, e.g., something like
def for_user_or_public(query, author_id) do
from d in query,
where: (d.author_id == ^author_id) or (d.public == ^true)
end
Can one do a disjunctive search in Ecto – find records satisfying THIS or THAT, e.g., something like
def for_user_or_public(query, author_id) do
from d in query,
where: (d.author_id == ^author_id) or (d.public == ^true)
end
Sure, that example of yours seems entirely valid too. What issue were you having?
Ah … I had memory failure. Public is defined in document.attributes
, which is a map. So I need the below instead – it does work.
def for_user_or_public(query, author_id) do
from d in query,
where: (d.author_id == ^author_id) or fragment("attributes @> '{\"public\": true}'")
end