Since Jason requires an explicit @derive where we specify which fields will be encoded, my initial idea was to whitelist the fields in one place (the ecto_encoders.ex file) instead of spread around schema files.
However, a much nicer solution would be to write a function that takes in a %Performance{} struct and recursively
removes Ecto.Association.NotLoaded fields (or at least set them to nil)
removes struct and meta fields
removes "private" fields that aren't needed to populate the registration form
Unfortunately, I can't figure out how to write such a filter since Elixir structs don't implement the Enumerable protocol 😕
Since Jason requires an explicit
@derive
where we specify which fields will be encoded, my initial idea was to whitelist the fields in one place (theecto_encoders.ex
file) instead of spread around schema files.However, a much nicer solution would be to write a function that takes in a
%Performance{}
struct and recursivelyUnfortunately, I can't figure out how to write such a filter since Elixir structs don't implement the Enumerable protocol 😕