Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stonehz opened this issue Jul 11, 2018 · 2 comments

Comments

@stonehz
Copy link

stonehz commented Jul 11, 2018

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 stonehz changed the title Documentation/Suggestion: Add example of how to use manually use track_changes? Documentation/Suggestion: Add example of how to manually use use track_changes? Jul 11, 2018
@stonehz stonehz changed the title Documentation/Suggestion: Add example of how to manually use use track_changes? Documentation/Suggestion: Add example of how to manually use track_changes? Jul 11, 2018
@stonehz stonehz changed the title Documentation/Suggestion: Add example of how to manually use track_changes? Documentation/Suggestion: Add example of how to manually use track_changes? Jul 11, 2018
@narrowtux
Copy link
Contributor

narrowtux commented Oct 9, 2018

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants