Missing hasMany child validation errors #1081

Closed
sbsurf opened this Issue Jul 9, 2013 · 2 comments

Comments

Projects
None yet
2 participants

sbsurf commented Jul 9, 2013

In rest_serializer.js, the extractValidationErrors method only returns errors whose names match direct attributes on the parent model submitted.

However, when a model (or transaction) save is performed on a model which also includes hasMany children as its attributes, errors that invalidate the children don't get returned, even though the parent model is (correctly) invalidated.

For example, I have 2 models:

App.Grower = DS.Model.extend
  name: DS.attr('string')
  addresses: DS.hasMany('App.Address')

App.Address = DS.Model.extend(
  line_1: DS.attr("string")
  line_2: DS.attr("string")
  city: DS.attr("string")
  region: DS.attr("string")
  postalCode: DS.attr("string")

  grower: DS.belongsTo("App.Grower")
)

When I get a 422 from the API (which is Rails by the way), the json response also includes the invalid fields. For example:

{"errors":{"name":["can't be blank"]}}

Here, I can find this error and its details in the errors collection on the parent model (Grower).

However, if the errors are on the addresses, which come back like this:

{"errors":{"addresses.line_1":["can't be blank"]}}

these errors cannot be used, as they're not added to the parent, and I don't seem to find them on the child either.

Is there a down side to including child errors in the parent model's errors collection? Or am I missing something?

Owner

wagenet commented Aug 14, 2013

@sbsurf I think the main reason we don't include other errors is because it's not clear at what point we'd clear them.

Owner

wagenet commented Oct 13, 2013

If someone has a proposal for how to handle this, that would be awesome. Closing this ticket for now.

wagenet closed this Oct 13, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment