From 84093f5a3300bb1189ffcb83c5f417c3f2390e02 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Thu, 24 Aug 2023 15:16:51 +0200 Subject: [PATCH] Make goal deletion possible with only goal id --- lib/plausible/goals.ex | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/plausible/goals.ex b/lib/plausible/goals.ex index 5e1c3827d..1d5cfebcc 100644 --- a/lib/plausible/goals.ex +++ b/lib/plausible/goals.ex @@ -118,14 +118,18 @@ defmodule Plausible.Goals do Otherwise, for associated funnel(s) consisting of minimum number steps only, funnel record(s) are removed completely along with the targeted goal. """ - def delete(id, site) do + def delete(id, %Plausible.Site{id: site_id}) do + delete(id, site_id) + end + + def delete(id, site_id) do result = Multi.new() |> Multi.one( :goal, from(g in Goal, where: g.id == ^id, - where: g.site_id == ^site.id, + where: g.site_id == ^site_id, preload: [funnels: :steps] ) ) @@ -162,7 +166,7 @@ defmodule Plausible.Goals do fn _ -> from g in Goal, where: g.id == ^id, - where: g.site_id == ^site.id + where: g.site_id == ^site_id end ) |> Repo.transaction()