documentcloud/backbone — Issue #1067: Make Model.url() check model's urlRoot first
Author: twashing
Created: 2012-03-04 15:09:27+00:00
State: open

I'm just putting this as an issue instead of a pull request because it's such a small change. I found when writing my app, if my model was part of a collection, saving the model would use the collection's url instead of the urlRoot I set in my model. That's due to [this line] (https://github.com/documentcloud/backbone/blob/master/backbone.js#L392) which takes the first non-null URL that it sees. I just propose altering the order in which it checks the urls, to be:

```javascript
url: function() {
var base;
base = this.urlRoot || getUrl(this.collection) || urlError();
if (this.isNew()) {
return base;
}
return base + (base.charAt(base.length - 1) == '/' ? '' : '/') + encodeURIComponent(this.id);
},
```