diff --git a/backbone.js b/backbone.js index 9b2a3af9..c52318a0 100644 --- a/backbone.js +++ b/backbone.js @@ -32,6 +32,11 @@ return child; }; + // Get a url as a property or as a function. + var getUrl = function(object) { + return _.isFunction(object.url) ? object.url() : object.url; + }; + // Backbone.Events // ----------------- @@ -136,7 +141,7 @@ // using Backbone's restful methods, override this to change the endpoint // that will be called. url : function() { - var base = this.collection.url(); + var base = getUrl(this.collection); if (this.isNew()) return base; return base + '/' + this.id; }, @@ -152,11 +157,6 @@ return new (this.constructor)(this.attributes()); }, - // Are this model's attributes identical to another model? - isEqual : function(other) { - return other && _.isEqual(this._attributes, other._attributes); - }, - // A model is new if it has never been saved to the server, and has a negative // ID. isNew : function() { @@ -621,7 +621,7 @@ // Backbone.sync = function(type, model, success, error) { $.ajax({ - url : model.url(), + url : getUrl(model), type : type, data : {model : model}, dataType : 'json', diff --git a/index.html b/index.html index a059e5b3..42c0a6b7 100644 --- a/index.html +++ b/index.html @@ -167,6 +167,7 @@
+ urlmodel.url()
+
+ Returns the relative URL where the model's resource would be located on
+ the server. If your models are located somewhere else, override this method
+ with the correct logic. Generates URLs of the form: "/[collection]/[id]".
+
+ A model with an id of 101, stored in a + Bindable.Collection with a url of "/notes", + would have this URL: "/notes/101" +
+ +
+ clonemodel.clone()
+
+ Create a new instance of a model with identical attributes.
+