Releases: jungsoft/paper_trail
Releases · jungsoft/paper_trail
v0.14.2
v0.14.1
Bug Fixes
- Fix serialization of associations when inserting the main record
v0.14.0
Summary
- Do not serialize nested associations when action is
update
andchanges
are empty - Add
event
anddata
info when serializing an association withaction == :replace
- Add
event
andchanges
info when serializing an association withaction != :replace
Details
Before, when serializing nested associations, we could have empty maps in the JSON, since we were only serializing the changes
from the Changeset. Now we have more information about whats going on on these associations.
Suppose we have a Post struct and a Comment struct that is associated with Post (with has_many
):
%Post{
title: "Example post",
description: "...",
comments: [
%{Comment{id: 1, text: "comment 1"},
%{Comment{id: 2, text: "comment 2"},
%{Comment{id: 3, text: "comment 3"},
]
}
# Now we update the posts with these attrs:
%{comments: [
%{id: 1, text: "comment 1 updated"},
%{id: 2, text: "comment 2"},
%{text: "new comment"},
]}
# before, the serialized `item_changes` in the `versions` table would be:
%{"comments" => [
{"text" => "comment 1 updated"},
{}, # this is the comment 2, without any changes
{}, # This is the comment 3, deleted because it was not in the attrs and there's no changes in the Changeset. changeset.action is set to replace
{"text" => "new comment"},
]}
# now, it will be serialized as this:
%{"comments" => [
{"event" => "update", "changes" => %{"text" => "comment 1 updated"}},
{"event" => "replace", "data" => %{"text" => "comment 3"}},
{"event" => "insert", "changes" => %{"text" => "new comment"}},
]}
# Notice that we removed serialization of associations with empty changes when it's an update action.
v0.13.0
Require Ecto 3.9