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

Originator relationship not working #36

Closed
joshchernoff opened this issue Feb 14, 2018 · 3 comments
Closed

Originator relationship not working #36

joshchernoff opened this issue Feb 14, 2018 · 3 comments

Comments

@joshchernoff
Copy link

joshchernoff commented Feb 14, 2018

I can see that I'm storing the originator_id and I have the config set to use "user" correct as I can use the name user for the origininator

IE |> PaperTrail.insert(user: user) and again I can see the id being set correctly in the db.

But when I try to preload or call upon the originator thats where I hit a problem.


{:ok, results} = cs |> PaperTrail.insert(user: user)

version = results[:version]

version |> IO.inspect
 --->
%PaperTrail.Version{
  __meta__: #Ecto.Schema.Metadata<:loaded, "versions">,
  event: "insert",
  id: 12,
  inserted_at: ~N[2018-02-14 19:12:08.399937],
  item_changes: %{
   ...
  },
  item_id: 31,
  item_type: "Client",
  meta: nil,
  origin: nil,
  originator_id: 1
}

version.user
** (KeyError) key :user not found in: %PaperTrail.Version{...}

version.originator
** (KeyError) key :originator not found in: %PaperTrail.Version{...}

version.originator_id
--> 1

version |> Repo.preload(:user)
** (ArgumentError) schema PaperTrail.Version does not have association :user

version |> Beffect.Repo.preload(:originator)
** (ArgumentError) schema PaperTrail.Version does not have association :originator

Not sure what I'm missing here.

Spec:

  • Elixir 1.6.0
  • Phoenix 1.3
  • ecto 2.2.8
  • paper_trail 0.7.7
@joshchernoff
Copy link
Author

joshchernoff commented Feb 14, 2018

Its the condition that is preventing the belongs to.
https://github.com/izelnakri/paper_trail/blob/master/lib/version.ex#L21

I removed the condition locally and I no longer have an issue, but its odd because if I run the condition it looks as if it should render true. So I don't know why the condition is failing to set the belongs_to correctly.

@joshchernoff
Copy link
Author

Ok, I think I may have found the issue, the deps compiled before I added config but then they didnt recompile. Since you will need to recompile the deps after you update the config/config it maybe worth noting in the READ ME.

@izelnakri
Copy link
Owner

I'm glad that you've found this issue and included in your pull request. I will review and merge it to README.

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

No branches or pull requests

2 participants