I have the following query:
defmodule ChampionshipResults do
....
def preload_assocs_by_league(query, league_id) do
from cr in query,
join: c in assoc(cr, :championship),
join: p in assoc(cr, :fantasy_player),
left_join: r in assoc(p, :roster_positions),
left_join: f in assoc(r, :fantasy_team),
where: f.fantasy_league_id == ^league_id,
where: r.active_at < c.championship_at,
where: (r.released_at > c.championship_at or is_nil(r.released_at)),
preload: [:championship],
preload: [fantasy_player: {p, roster_positions: {r, fantasy_team: f}}]
end
end
fantasy_player has_many roster_positions
I want to return all championship_results preloaded with any roster_positions meeting my where clauses criteria. However, championship_results that do not have any roster_positions are currently not returned.
In other functions, I’ve used the pin operator to preload a roster_position query, but I can’t figure out how to do it since I need dates from my championship table which I need to join through championship_results.
Does anyone have any recommendations for how I can write the query?
Thanks!
Axel