documentcloud/backbone — Issue #917: "Can't create an invalid model"
Author: terryroe
Created: 2012-01-31 22:28:44+00:00
State: open

Version 0.9.0 introduced a new feature that disallows creating models that do not pass validation. This seems to limit the ability to use models as dynamic containers of information. If you have validation rules that specify what a valid model is, it seems the model must now always conform to those rules. If you can only store valid models, you can't keep invalid information available for redisplay to a user so they can edit or correct it. If information comes from the server that is invalid, creating the model would just fail. (I believe this is the case, though have not tested the server scenario.)

When the new model is created and it fails validation, there is no way to find out why the model creation failed because an Error is thrown instead of an error event being fired.

The functionality in 0.5.3 had validate() running only at what seemed logical points in the model's lifecycle. This was on set() (unless you set the 'silent' flag) and on save(). You were able to more easily manage when validation would run.

The way Rails handles models is that validation only occurs at certain, specific times, and those can general be overridden. You can create and empty model for use in a "new" form, etc. I think this is closer to the expectations most folks have for the way models should work.

The way 0.9.0 works seems limiting. (I'm sure there are other aspects I'm leaving out, but I wanted to get the discussion rolling.) Hopefully someone can point out the flaws in my argument, and we can discuss what the validation for models should look like.