I’m using Ecto.Query.dynamic/2
to conditionally build queries piece-meal.
Following this: https://hexdocs.pm/ecto/dynamic-queries.html#dynamic-and-joins
The examples work, but they are a bit basic. I have some tested joins. For example:
dynamic([authors: a], ^dynamic and a.name == ^value)
I actually also need to load each author’s :books
as b
, and check one of b’s columns against a list of values.
I tried:
dynamic([authors: {a, books: b}], ^dynamic and b.publisher_id in ^ids)
But this gives:
(Ecto.Query.CompileError) binding list should contain only variables or `{as, var}` tuples, got: {:author, {a, [books: b]}}