diff --git a/backbone.js b/backbone.js index 824c19aa..887e1da5 100644 --- a/backbone.js +++ b/backbone.js @@ -291,7 +291,7 @@ // using Backbone's restful methods, override this to change the endpoint // that will be called. url : function() { - var base = getUrl(this.collection); + var base = this.urlBase || getUrl(this.collection); if (this.isNew()) return base; return base + (base.charAt(base.length - 1) == '/' ? '' : '/') + this.id; }, diff --git a/test/model.js b/test/model.js index 6827997e..af379b9a 100644 --- a/test/model.js +++ b/test/model.js @@ -65,6 +65,16 @@ $(document).ready(function() { equals(failed, true); doc.collection = collection; }); + + test("Model: url when using urlBase", function() { + var Model = Backbone.Model.extend({ + urlBase: '/collection' + }); + var model = new Model(); + equals(model.url(), '/collection'); + model.set({id: '1'}); + equals(model.url(), '/collection/1'); + }); test("Model: clone", function() { attrs = { 'foo': 1, 'bar': 2, 'baz': 3};