Methods .fetch()
, .save()
and .destroy()
on Backbone.Model
are checking if the model has .sync()
defined and if yes it will get called otherwise Backbone.sync()
will get called (see the last lines of the linked source code).
So one of the solutions is to implement .sync()
method.
Example:
var User = Backbone.Model.extend({
// ...
methodToURL: {
'read': '/user/get',
'create': '/user/create',
'update': '/user/update',
'delete': '/user/remove'
},
sync: function(method, model, options) {
options = options || {};
options.url = model.methodToURL[method.toLowerCase()];
return Backbone.sync.apply(this, arguments);
}
}