Baseline ID changed
Does the fetch model behavior, in particular the setting of the model ID, changed between 1.1.0 and 1.1.2?
I have checked the changelog and found nothing suitable.
The following functions no longer work:
var Wibble = Backbone.Model.extend({
urlRoot: 'rest/wibble',
idAttribute: 'wibbleId'
});
var model = new Wibble();
model.id = 1;
model.fetch()
He requests / rests / wibble, not / rest / wibble / 1 as he is used to.
Examples: I used url () rather than fetch () to demonstrate
source to share
The model creates its url by adding /[id]
when the model is not new:
url: function() {
var base = _.result(this, 'urlRoot') ||
_.result(this.collection, 'url') ||
urlError();
if (this.isNew()) return base;
return base.replace(/([^\/])$/, '$1/') + encodeURIComponent(this.id);
}
but it seems that model.isNew
changed between 1.1.0 and 1.1.2
-
isNew: function() { return this.id == null; },
-
isNew: function() { return !this.has(this.idAttribute); },
Now the check only considers the property idAttribute
and the property id
more.
The setup idAttribute
, as in example 1.1.2, is probably the safest bet:
model.set('wibbleId', 123);
source to share