PDA

View Full Version : Delete with rest proxy sends whole record



pedwards
30 Jan 2014, 11:55 AM
Hi,

I have a model with a rest proxy and I've just noticed that when I call MyStore.remove(record) it is sending the whole record in the request body. My API URL is:

/api/MyStore

And, it calls:

DELETE /api/MyStore/<ID>

This is enough information to remove the record. Is it supposed to send the record as well? Or, is there a way to control what is sent?

Thanks,
Paul

skirtle
30 Jan 2014, 1:06 PM
See the source for allowWrite:

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Operation-method-allowWrite

The default implementation will write the model for everything but a read. You can easily override it.

If you want to see where it's used, see the source for Ajax proxy.

pedwards
31 Jan 2014, 4:59 AM
See the source for allowWrite:

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Operation-method-allowWrite

The default implementation will write the model for everything but a read. You can easily override it.

If you want to see where it's used, see the source for Ajax proxy.

Thank you for your reply (it's good to know I'm not doing anything wrong!)

Finally, how would you override it? By modifying the prototype? E.g.

Ext.data.Operation.prototype.allowWrite = function () {
return this.action != 'read' && this.action != 'destroy';
};

Or, is there a better way?

Thanks again,
Paul

skirtle
31 Jan 2014, 5:06 AM
Not sure about 'better' but more idiomatic:


Ext.define('MyApp.Operation', {
override: 'Ext.data.Operation', // Note override, not extend

allowWrite: function() {
...
}
});