ex_audit
ex_audit copied to clipboard
Documentation/Suggestion: Add example of how to manually use track_changes?
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.
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, akaMyApp.Repo
-
adapter
is the Ecto database adapter, this is obtainable byMyApp.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
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