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

Encoding problems with many_to_many for PaperTrail.update/2 #7

Closed
joshuataylor opened this issue Jan 28, 2017 · 3 comments
Closed

Encoding problems with many_to_many for PaperTrail.update/2 #7

joshuataylor opened this issue Jan 28, 2017 · 3 comments

Comments

@joshuataylor
Copy link
Contributor

joshuataylor commented Jan 28, 2017

So I'm doing something like

ids = [1,2,3]
items = MyApp.Item |> where([p], p.id in ^ids) |> Repo.all
changeset = Ecto.Changeset.put_assoc(changeset, :items, items)

PaperTrail.update changeset

Now, when saving, it gives me the following error:
** (Poison.EncodeError) unable to encode value: {:assoc, %Ecto.Association.BelongsTo{cardinality: :one, defaults: [], field: :something, on_cast: nil, on_replace: :raise, owner: MyApp.Something, owner_key: :something_id, queryable: MyApp.Something, related: MyApp.Something, related_key: :id, relationship: :parent, unique: true}}

I've tried setting a custom encoder for my model/schema in my app with poison, but it doesn't seem to work for paper_trail.

What's the best way to handle this?

@izelnakri
Copy link
Owner

There is no relationship called :changeset in paper_trail. PaperTrail.insert , update and delete functions wrap your record insertion/edit in a database transaction and creates a row with associated data in the versions table. You shouldnt change the data manually like this.

@izelnakri
Copy link
Owner

izelnakri commented Feb 1, 2017

closing this issue if you are ok with it, let me know if you would like it reopened

@jeremyjh
Copy link

@izelnakri We're struggling with the same issue. Joshua is not updating the data manually; he is using Ecto's put_assoc to populate a changeset. Papertrail does operate on changesets created with cast. If associations are not supported that is fine I guess but is this something you'd be open to a PR addressing (if its feasible) ?

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

3 participants