Backbone.ModelMorph
Backbone.ModelMorph copied to clipboard
not compatible with backbone 1.10
backbone 1.10 remove model.change() method so my patch is to call directly _model.set with the result of _schema[key].set
also support for 1 to 1 mapping where _schema[key].set return a value instead of an array
return this._model.set(key, this._schema[key].set(value), options);
// else we expect back an array of values to set each require
var vals = this._schema[key].set(value);
- _.extend(options, {silent: true});
- _.each(vals, function(val, ind) {
- this.set(this._schema[key].require[ind], val, options);
- }, this);
- this._model.change();
+ if (_.isArray(vals)) {
+ _.each(vals, function(val, ind) {
+ this._model.set(this._schema[key].require[ind], val, options);
+ }, this);
+ } else { // require only have one input, so one to one mapping
+ this._model.set(this._schema[key].require[0], vals, options);
+ }
+
}
},
Is this passing the tests? the idea of using silent was to avoid recursive change events being fired.
It might be better just to re-implement the old change method, but it's been a little while since I've used Backbone now so happy to take your word for it if it's all working for you.
Can you send a pull request?