ja_serializer icon indicating copy to clipboard operation
ja_serializer copied to clipboard

EctoErrorSerializer doesn't render errors from relationships and embedded objects

Open lucasmazza opened this issue 5 years ago • 4 comments

This was reported on #249 but the issue and PR are closed without being merged and released. EctoErrorSerializer.format/3 calls changeset.errors directly instead of using traverse_errors/2 to walk through the changeset data to collect nested errors and render properly. It is possible that we can bring this fix back?

lucasmazza avatar Aug 14 '19 15:08 lucasmazza

I think it got missed as this project changed hands around that time and it just fell through the cracks. I'd definitely be interested in supporting that if there's a good use case for it. Without JSON API having good support for creating nested records in v1.0 of the spec, what is your use case? I just want to make sure I understand how it would be used so the tests reflect that.

beerlington avatar Aug 16 '19 13:08 beerlington

@beerlington we have a schema with the following relationships:

defmodule MyApp.Client do
  use Ecto.Schema
  import Ecto.Changeset

  schema "clients" do
    has_many :addresses, MyApp.Address
    embeds_one :document, MyApp.Document
  end
end

Our API accepts the addresses and document properties inside the clients document, and we want to respond with the validation errors of those associations as expected. Ecto won't store the errors on the clients changeset, but we need to traverse the inner Changesets using traverse_errors to collect those errors when rendering it on the API.

lucasmazza avatar Aug 16 '19 14:08 lucasmazza

I would also be interested in seeing this implemented.

theoks avatar Aug 26 '20 15:08 theoks

What workarounds are you folks using until this is implemented?

tadast avatar Aug 26 '20 16:08 tadast