Skip to content

Commit

Permalink
Support casting association list (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
rschef authored Oct 28, 2020
1 parent 5773a0c commit 43678cf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/paper_trail/serializer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 43678cf

Please sign in to comment.