maxmalov
maxmalov

Reputation: 510

RESTful Model, get rid of the id query param in the GET request

I'm a little bit stuck here. My model code is

Ext.define('MyFancyModel', {
    extend: 'Ext.data.Model',

    fields: [
        { name: 'id', type: 'string' },
        { name: 'name', type: 'string' }
    ],

    proxy: {
        type: 'rest',
        url: '/fancymodel',
        noCache: false
    }
});

When I try to load data by id using

Ext.ModelManager.getModel('MyFancyModel').load('some-id', {});

the request url is /fancymodel/some-id?id=some-id which is obviously not correct. So how can I achieve the right request url: /fancymodel/some-id without any patches or overrides?

EDIT:

jsfiddle

In the developer console you can see failed GET request

http://fiddle.jshell.net/fancymodel/some-id?id=some-id

EDIT:

Thread on the Sencha forum

Upvotes: 1

Views: 1124

Answers (1)

user1636522
user1636522

Reputation:

I haven't found any ExtJS solution, so I have written a small patch (not sure it works in every situations) :

Ext.override(Ext.data.proxy.Rest, {
    buildUrl: function (request) {
        delete request.params.id;
        return this.callParent(arguments);
    }
});

The standard way :

Ext.define('MyPatches.data.proxy.Rest', {
    override: 'Ext.data.proxy.Rest',
    buildUrl: function (request) {
        delete request.params.id;
        return this.callParent(arguments);
    }
});

Upvotes: 2

Related Questions