Hi all,
I’ve got the following SQL statement that I’d like to Ecto-ize
SELECT * from organizations WHERE id NOT IN (SELECT id from memberships where user_id = 123)
I’ve got it working with fragment
:
q = from o in Organization,
where: o.private == false and fragment("id NOT IN (select id from memberships where user_id = ?)", ^id)
Repo.all(q)
I know that we can’t use subquery
in a WHERE clause, and using joins are recommended, but I can’t figure out how to convert the above query into a JOIN.
Thanks,
Andrew