Skip to content

Commit

Permalink
Add new add_prefix function in paper_trail module
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dreamingechoes committed Jul 27, 2017
1 parent 968a0b0 commit e9f28cb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/paper_trail.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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

0 comments on commit e9f28cb

Please sign in to comment.