Closed axelclark closed 8 years ago
roster_status: "active", "dropped", "traded" released_at:
"active" is default for any new RosterPosition Waiver claim: "dropped" & update released_at date/time Trade: "traded" & update released_at date/time
Need to update existing queries with where r.roster_status == "active" Need to test the default is working when a player is drafted Need to test existing records get default "active"
def right_join_players_by_league(query, fantasy_league_id) do
from t in query,
left_join: r in RosterPosition,
on: r.fantasy_team_id == t.id and t.fantasy_league_id == ^fantasy_league_id,
right_join: p in assoc(r, :fantasy_player),
inner_join: s in assoc(p, :sports_league),
select: %{team_name: t.team_name, player_name: p.player_name,
league_name: s.league_name},
order_by: [s.league_name, p.player_name]
end
def all_players_with_owners(query, fantasy_league_id) do
from p in query,
left_join:
fragment(
(
@roster_position r
InnerJoin
@fantasy_team t
ON
r.fantasy_team_id = t.id and t.fantasy_league_id = ?, ^fantasy_league_id
WHERE
r.roster_status = ?, "active"
)
)
ON: p.id = r.fantasy_player_id,
select: %{team_name: t.team_name, player_name: p.player_name,
league_name: s.league_name},
order_by: [s.league_name, p.player_name]
end
When a player is dropped or traded, the RosterPosition is updated in a column rather than deleted from the database.