Skip to content

Commit

Permalink
Propagate options to repo actions in delete functions
Browse files Browse the repository at this point in the history
This will allow us to delete records with on cascade relations in the
same schema (it’s not possible at this moment).
  • Loading branch information
dreamingechoes committed Aug 9, 2017
1 parent ead9cc6 commit 64231d7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/paper_trail.ex
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ defmodule PaperTrail do
"""
def delete(struct, options \\ [origin: nil, meta: nil, originator: nil, prefix: nil]) do
transaction = Multi.new
|> Multi.delete(:model, struct)
|> Multi.delete(:model, struct, options)
|> Multi.run(:version, fn %{} ->
version = make_version_struct(%{event: "delete"}, struct, options)
@repo.insert(version)
@repo.insert(version, options)
end)
|> @repo.transaction
|> @repo.transaction(options)

case transaction do
{:error, :model, changeset, %{}} -> {:error, Map.merge(changeset, %{repo: @repo})}
Expand All @@ -218,9 +218,9 @@ defmodule PaperTrail do
"""
def delete!(struct, options \\ [origin: nil, meta: nil, originator: nil, prefix: nil]) do
@repo.transaction(fn ->
model = @repo.delete!(struct)
model = @repo.delete!(struct, options)
version_struct = make_version_struct(%{event: "delete"}, struct, options)
@repo.insert!(version_struct)
@repo.insert!(version_struct, options)
model
end) |> elem(1)
end
Expand Down

0 comments on commit 64231d7

Please sign in to comment.