documentcloud/backbone — Issue #1049: Can't override {silent: true} on create
Author: toddself
Created: 2012-02-25 20:06:55+00:00
State: open

I'm trying to force validation on model creation.

We're bootstrapping the data into the models when the page loads to cut down on XHR traffic and speed up the interface and while our back-end is good now, there was a time when there was no checking on input data, which means we have invalid data stored in our database.

I've got my own validation framework set up, which works AFTER the model has been validated, but when I try to pass` {silent: false}` when creating a new object, validation doesn't occur.

This seems because line 185 is:

```javascript
this.set(attributes, {silent: true});
```

So no matter what my options are for create, set always receives `{silent: true}` which means I can't for validation on create, which creates some oddities. (Using http://github.com/toddself/Backbone.Validator to perform validation)

Example:

```javascript
var TestModel = Backbone.Model.extend({
validators: {
title: {
min_length: 5,
is_type: 'string'
}
},
initialize: function(){
this.on('error', this.log);
},
log: function(model, error){
console.log(error);
}
});

// unable to set bad titles
var t = new TestModel({title: 'this should work'});
t.get('title');
"this should work"

t.set('title', false);
['Expected false to be of type string for title']

t.get('title');
"this should work"

// can create when silent: true
var t2 = new TestModel({title: false});
t2.get('title');
false

t2.isValid();
true

t2.set('title', 'this is a good title as well');
t2.get('title')
"this is a good title as well"

t2.set('title', false);
['Expected false to be of type string for title']

t2.get('title');
"this is a good title as well'

// but can still create when silent: false
var t3 = new TestModel({title: false}, {silent: false});
t3.get('title');
false

t3.isValid();
true

t3.set('title', 'this is a good title as well');
t3.get('title')
"this is a good title as well"

t3.set('title', false);
['Expected false to be of type string for title']

t3.get('title');
"this is a good title as well'
```

Is this by design? I see the change logs had forcing validation on new objects for a while, but it was reverted in 0.9.1. Will we be able to override the hard coded `{silent: true}` or am I just missing something really obvious and I can force validation on create?

Any help is appreciated!