From 3ef7861f229a98f84b23c748d565774de76499c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro?= Date: Fri, 7 Jun 2024 01:57:34 +0200 Subject: [PATCH] insert_or_update for champion picked summoner spell fact --- .../facts/champion_picked_summoner_spell/repo.ex | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/lol_analytics/lib/lol_analytics/facts/champion_picked_summoner_spell/repo.ex b/apps/lol_analytics/lib/lol_analytics/facts/champion_picked_summoner_spell/repo.ex index 80a21de..ffba1a6 100644 --- a/apps/lol_analytics/lib/lol_analytics/facts/champion_picked_summoner_spell/repo.ex +++ b/apps/lol_analytics/lib/lol_analytics/facts/champion_picked_summoner_spell/repo.ex @@ -26,11 +26,22 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo do _champion = ChampionRepo.get_or_create(attrs.champion_id) _player = PlayerRepo.get_or_create(attrs.puuid) _spell = SummonerSpellRepo.get_or_create(attrs.summoner_spell_id) - changeset = Schema.changeset(%Schema{}, attrs) + + prev = + from(f in Schema, + where: + f.match_id == ^attrs.match_id and + f.champion_id == ^attrs.champion_id and + f.summoner_spell_id == + ^attrs.summoner_spell_id + ) + |> Repo.one!() + + changeset = Schema.changeset(prev, attrs) IO.inspect(attrs) - Repo.insert(changeset) + Repo.insert_or_update(changeset) |> IO.inspect() end