afeld / backbone-nested

A plugin to make Backbone.js keep track of nested attributes - looking for maintainers! https://github.com/afeld/backbone-nested/issues/157
https://afeld.github.com/backbone-nested/
MIT License
444 stars 83 forks source link

model.clear() does not work when model is invalid #141

Open pgilad opened 9 years ago

pgilad commented 9 years ago

model.clear() does not work when model does not pass validation: https://github.com/afeld/backbone-nested/blob/master/backbone-nested.js#L118-L120

  1. What is the logic behind even checking if model is valid when clearing it?
  2. this.validate is supposed to return undefined. What is the reason behind this check?
  3. Code does not make sense.
fabien commented 8 years ago

Just bumped into to this issue myself - doesn't make any sense ...

jacobbuck commented 8 years ago

We just noticed this too. It does seem a bit odd, but after some further investigation it's actually replicating existing Backbone behaviour:

Backbone.Model.prototype.clear() will run Backbone.Model.prototype.set(), which will validate the model before setting.

You can get past this by passing the validate option as false:

someNestedModel.clear({validate: false});