diff --git a/README.md b/README.md index 7e9e3d4e..474ded61 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ The library source code is minimal and well tested. It is suggested to read the ```elixir def deps do - [{:paper_trail, "~> 0.6.0"}] + [{:paper_trail, "~> 0.7.0"}] end ``` @@ -116,7 +116,7 @@ The library source code is minimal and well tested. It is suggested to read the 3. install and compile your dependency: - ```mix deps.get && mix deps.compile``` + ```mix deps.get && mix compile``` 4. run this command to generate the migration: @@ -160,7 +160,7 @@ PaperTrail.insert(new_user_changeset, origin: "facebook_registration") ``` ### Originator relationships -You can specify setter/originator relationship to paper_trail versions with ```originator_id``` assignment. This feature is only possible by specifying `:originator` keyword list for your application configuration: +You can specify setter/originator relationship to paper_trail versions with ```originator``` assignment. This feature is only possible by specifying `:originator` keyword list for your application configuration: ```elixir # in your config/config.exs @@ -168,14 +168,18 @@ You can specify setter/originator relationship to paper_trail versions with ```o # For most applications originator should be the user since models can be updated/created/deleted by several users. ``` -Then originator name could be used for querying and preloading however originator setting must be done via originator_id: +Then originator name could be used for querying and preloading. Originator setting must be done via ```:originator``` or originator name that is defined in the paper_trail configuration: ```elixir user = create_user() -PaperTrail.insert(changeset, originator_id: user.id) -{:ok, result} = PaperTrail.update(edit_changeset, originator_id: user.id) +# all these set originator_id's for the version records +PaperTrail.insert(changeset, originator: user) +{:ok, result} = PaperTrail.update(edit_changeset, originator: user) +# or you can use :user in the params instead of :originator if this is your config: +# paper_trail originator: [name: :user, model: YourApplication.User] +{:ok, result} = PaperTrail.update(edit_changeset, user: user) result[:version] |> Repo.preload(:user) |> Map.get(:user) # we can access the user who made the change from the version thanks to originator relationships! -PaperTrail.delete(edit_changeset, originator_id: user.id) +PaperTrail.delete(edit_changeset, user: user) ``` Also make sure you have the foreign-key constraint in the database and in your version migration file. @@ -263,7 +267,7 @@ edited_company = Company.changeset(company, %{name: "Acme Inc."}) |> PaperTrail. Additionally, you can put a null constraint on ```origin``` column, you should always put an ```origin``` reference to describe who makes the change. This is important for big applications because a model can change from many sources. ### Storing version meta data -You might want to add some meta data that doesn't belong to ``originator_id`` and ``origin`` fields. Such data could be stored in one object named ```meta``` in paper_trail versions. Meta field could be passed as the second optional parameter to PaperTrail.insert/2, PaperTrail.update/2, PaperTrail.delete/2 functions: +You might want to add some meta data that doesn't belong to ``originator`` and ``origin`` fields. Such data could be stored in one object named ```meta``` in paper_trail versions. Meta field could be passed as the second optional parameter to PaperTrail.insert/2, PaperTrail.update/2, PaperTrail.delete/2 functions: ```elixir company = Company.changeset(%Company{}, %{name: "Acme Inc."}) @@ -274,7 +278,7 @@ edited_company = Company.changeset(company, %{name: "Acme LLC"}) # or even with an originator: user = create_user() deleted_company = Company.changeset(edited_company, %{}) - |> PaperTrail.delete(origin: "worker:github", originator: user.id, meta: %{slug: "acme-llc", important: true}) + |> PaperTrail.delete(origin: "worker:github", originator: user, meta: %{slug: "acme-llc", important: true}) ``` ## Suggestions diff --git a/config/test.exs b/config/test.exs index b065d185..07c32d77 100644 --- a/config/test.exs +++ b/config/test.exs @@ -2,7 +2,7 @@ use Mix.Config config :paper_trail, ecto_repos: [PaperTrail.Repo] -config :paper_trail, repo: PaperTrail.Repo +config :paper_trail, repo: PaperTrail.Repo, originator: [name: :user, model: User] config :paper_trail, PaperTrail.Repo, adapter: Ecto.Adapters.Postgres, diff --git a/doc/404.html b/doc/404.html index b901414e..de46d845 100644 --- a/doc/404.html +++ b/doc/404.html @@ -5,7 +5,7 @@ -
Deletes a record from the database with a related version insertion in one transaction
@@ -139,7 +139,7 @@Inserts a record to the database with a related version insertion in one transaction
@@ -148,7 +148,7 @@Updates a record from the database with a related version insertion in one transaction
@@ -184,7 +184,7 @@