From 43678cfc05276c0ede88b1f60663f048ff57ee36 Mon Sep 17 00:00:00 2001 From: Rafael Scheffer Date: Wed, 28 Oct 2020 10:34:51 -0300 Subject: [PATCH] Support casting association list (#9) --- lib/paper_trail/serializer.ex | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/paper_trail/serializer.ex b/lib/paper_trail/serializer.ex index b403d117..22081954 100644 --- a/lib/paper_trail/serializer.ex +++ b/lib/paper_trail/serializer.ex @@ -117,11 +117,19 @@ defmodule PaperTrail.Serializer do |> List.first() end - @spec serialize(nil | Ecto.Changeset.t() | struct, options, String.t()) :: nil | map + @spec serialize( + nil | Ecto.Changeset.t() | struct() | [Ecto.Changeset.t() | struct()], + options(), + String.t() + ) :: nil | map() | [map()] def serialize(model, options, event \\ "insert") def serialize(nil, _options, _event), do: nil + def serialize(list, options, event) when is_list(list) do + Enum.map(list, &serialize(&1, options, event)) + end + def serialize( %Ecto.Changeset{data: %schema{}, changes: changes}, options,