From e9f28cbd61f670b9a6dd9a06fa6d496df0a76e1d Mon Sep 17 00:00:00 2001 From: Ivan Gonzalez Date: Thu, 27 Jul 2017 16:20:11 +0200 Subject: [PATCH] Add new add_prefix function in paper_trail module This new function will allow the user to add information to the Ecto meta :prefix in order to use a different tenant for the operation on the version struct. --- lib/paper_trail.ex | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/paper_trail.ex b/lib/paper_trail.ex index 20253f8e..03c9ab35 100644 --- a/lib/paper_trail.ex +++ b/lib/paper_trail.ex @@ -267,7 +267,7 @@ defmodule PaperTrail do end, origin: options[:origin], meta: options[:meta] - } + } |> add_prefix(options[:prefix]) end defp make_version_struct(%{event: "update"}, changeset, options) do originator_ref = options[@originator[:name]] || options[:originator] @@ -282,7 +282,7 @@ defmodule PaperTrail do end, origin: options[:origin], meta: options[:meta] - } + } |> add_prefix(options[:prefix]) end defp make_version_struct(%{event: "delete"}, model, options) do originator_ref = options[@originator[:name]] || options[:originator] @@ -297,7 +297,7 @@ defmodule PaperTrail do end, origin: options[:origin], meta: options[:meta] - } + } |> add_prefix(options[:prefix]) end defp get_sequence_from_model(changeset) do @@ -318,4 +318,7 @@ defmodule PaperTrail do relationships = model.__struct__.__schema__(:associations) Map.drop(model, [:__struct__, :__meta__] ++ relationships) end + + defp add_prefix(changeset), do: changeset + defp add_prefix(changeset, prefix), do: Ecto.put_meta(changeset, prefix: prefix) end