Skip to content

Releases: jungsoft/paper_trail

v0.14.2

14 Aug 09:39
bcc4a38
Compare
Choose a tag to compare

There were still some cases where empty changes in associations were being created, such as when virtual fields are involved, since virtual fields are only removed from the changes after serialization. (#10)

v0.14.1

31 Mar 14:27
a5746c0
Compare
Choose a tag to compare

Bug Fixes

  • Fix serialization of associations when inserting the main record

v0.14.0

02 Mar 12:17
bc3e52e
Compare
Choose a tag to compare

Summary

  • Do not serialize nested associations when action is update and changes are empty
  • Add event and data info when serializing an association with action == :replace
  • Add event and changes info when serializing an association with action != :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

10 Nov 16:24
eee67da
Compare
Choose a tag to compare

Require Ecto 3.9