ex_audit icon indicating copy to clipboard operation
ex_audit copied to clipboard

Documentation/Suggestion: Add example of how to manually use track_changes?

Open stonehz opened this issue 6 years ago • 2 comments

We started using the library and on a specific scenario, we have to use Ecto.Multi . Looking through the documentation/code, the usage of ExAudit.Tracking.track_change implies that user will build the resulting_struct through Ecto.Repo.Schema and that is clear unless you go through the codebase. Also, Ecto Documentation does not expose Ecto.Repo.Schema which makes the usage trickier.

btw, plugin works great on basic operations.

stonehz avatar Jul 11 '18 13:07 stonehz

Yes, I'll get to that some time.

For the meantime, these are the arguments you have to pass:

track_change(module, adapter, action, changeset, resulting_struct, opts)

  • module is the repository module, aka MyApp.Repo
  • adapter is the Ecto database adapter, this is obtainable by MyApp.Repo.__adapter__
  • action is either :insert or :update
  • changeset is the changeset that was inserted or updated
  • resulting_struct is what was returned by Repo.insert/Repo.update, this is where it will get the id from if the action was an insert
  • opts is a list of options, ex_audit_custom is accepted here

narrowtux avatar Oct 09 '18 13:10 narrowtux

Note that deep changes will not be tracked with this, because ex_audit is abusing the fact that ecto calls repo.insert/repo.update for those recursively

narrowtux avatar Oct 09 '18 13:10 narrowtux