Oh my god, hahaha ![]()
Yeah, I guess that makes A LITTLE (a lot) more sense, thank you!
But the thing is, I was trying to bring the preload to the from function because I wanted to create a custom map using select in the end of the query, and I thought I wouldn’t be able to preload it afterwards if the result of the query would not be a Ecto struct.
But if I go:
from u in User,
join: r in assoc(u, :user_group_relationships),
on: not is_nil(r.role),
join: g in assoc(r, :group),
where: g.id == ^id,
preload: [...],
select: %{name: u.name, role: r.role}
I get:
** (Ecto.QueryError) the binding used in `from` must be selected in `select` when using `preload` in query
I don’t quite understand what it means…
I know the preload works cause if I just use select: u it returns the list of User structs fine and if I select a tuple (i.e. select: {u, r.role}) I get the results I want, but then I have to map the result to create the new map for each element returned, which doesn’t seem right to me.
Is there a way to do that new map straight from select?


















