I have a Conversation model and a view that displays this model. This model is fetched from the server without any problem (the url property works fine then), and the view is rendered. However, when I attempt to destroy the model in a function of the view, I get the error 'A "url" property or function must be specified', even though when I display said url right before the destroy call, it is exactly the url it should be.
Here is the code for the model:
MessageManager.models.Conversation = Backbone.Model.extend({
defaults: {
uid: '',
title: '',
messages: [],
users: [],
dateUpdated: null,
isNew: true,
message: ''
},
url: function(){
var url = '/api/conversations';
if(this.get('uid').length > 0) url += '/'+this.get('uid');
return url;
}
});
And the view:
MessageManager.views.ConversationFull = Marionette.CompositeView.extend({
template: this.template(MessageManager.templates.ConversationFull),
childView: MessageManager.views.MessageListItem,
childViewContainer: '#message-container',
events: {
'click a#btn-delete-conversation': 'deleteConversation'
},
deleteConversation: function(e){
e.preventDefault();
var self = this;
console.log(self.model.url()); //This returns a correct url
self.model.destroy({//This fires the error
error: function(model, result, xhr){
console.log(result.responseText);
},
success: function(model, response, options){
MessageManager.conversations.sync();
AMMain.router.pNavigate('welcome/');
}
});
}
});
Can anyone give some insight on how to resolve this problem? Is there something wrong in the way I declare the model?
EDIT: It should be noted that other calls (like fetch or sync) on this model fire the same error, even though the original fetch works without a problem.
EDIT2: Well, not completely out of the frying pan yet, but I changed the way I defined the model's url, using urlRoot and the "id" attribute, and now the DELETE request is sent to the server without error.