I am attempting to create a system in a phoenix web app using ecto where I have a many-to-many relationship between table A
and table B
. Table C
is used to create the join between these two.
problem
I need to perform a query where I take * from A
where there isn’t a relationship between A-B
where B.name in exclude
My current code
The first where works just fine, but the second one fails, even though when I IO.inspect
the query it is in there. I don’t get why the second one wouldn’t work if the first one does.
# include : [string]
# exclude : [string]
query
|> join(:inner, [a], ba in assoc(f, :bs))
|> join(:inner, [_, ba], b in assoc(ba, :as))
|> where([_, b], b.name in ^include)
|> where([_, b], b.name not in ^exclude)
|> group_by([f], f.id)