Reputation: 493
Has Model fetch behaviour, specifically setting the model id, changed between 1.1.0 and 1.1.2?
I've checked the changelog and can't find anything relevant.
The following no longer works:
var Wibble = Backbone.Model.extend({
urlRoot: 'rest/wibble',
idAttribute: 'wibbleId'
});
var model = new Wibble();
model.id = 1;
model.fetch()
It requests /rest/wibble rather than /rest/wibble/1 as it used to.
Examples: I've used url() rather than fetch() to demonstrate
Upvotes: 3
Views: 77
Reputation: 33364
A model builds its url by appending /[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 appears 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);
},
The check now only considers the property described by idAttribute
and no longer the id
property.
Setting your idAttribute
as you did in your 1.1.2 example is probably the safest bet:
model.set('wibbleId', 123);
Upvotes: 3