I have a model like this:
define([
'jquery',
'backbone'
], function ($) {
var MyModel = Backbone.Model.extend({
url: 'articles/',
initialize: function(){
}
});
return MyModel;
});
And this is the code for saving the object:
article = new Article();
status = t.currentTarget.textContent;
article.set('ready', {'status': status});
coords = this.model.get('location').coords;
article.set('geo', {'lat': coords.latitude, 'lng': coords.longitude});
article.save(null, { accessToken: true }).done(function(){
self.hideIcons();
});
But when I do the PATCH:
this.article.save({comment: comment}, {patch: true, accessToken: true});
The request is correctly PATCH, but the endpoint is wrong, the request is like this:
PATCH mydomain.com/articles/
As you can see, should be:
PATCH mydomain.com/articles/<last-model-id-created>/
Thanks.
Instead of setting the
Model.urlproperty, you should setModel.urlRoot. From the docs:If the model belongs to a collection, you can leave
Model.urlRootunspecified as well and setCollection.urlinstead.