vt-elixir / ja_serializer

JSONAPI.org Serialization in Elixir.
Other
640 stars 148 forks source link

EctoErrorSerializer doesn't render errors from relationships and embedded objects #329

Open lucasmazza opened 5 years ago

lucasmazza commented 5 years ago

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?

beerlington commented 5 years ago

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.

lucasmazza commented 5 years ago

@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.

theoks commented 4 years ago

I would also be interested in seeing this implemented.

tadast commented 4 years ago

What workarounds are you folks using until this is implemented?