Backbone.ModelMorph icon indicating copy to clipboard operation
Backbone.ModelMorph copied to clipboard

not compatible with backbone 1.10

Open jiixing opened this issue 12 years ago • 1 comments

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);
+        }
+
       }
     },

jiixing avatar Dec 09 '13 23:12 jiixing

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?

rhysbrettbowen avatar Dec 10 '13 00:12 rhysbrettbowen