PDA

View Full Version : [4.0.2a] Store not calling setModel



nextSTEP
31 Jan 2012, 1:44 AM
Hi,

I have a store with a proxy defined as follows:

proxy: {
type: "ajax",
url: "some url",
reader: {
type: "json",
root: "myRoot"
}
}

Now I found out that the reader won't get instantiated until I directly create the proxy:
(An error is thrown because there is no valid reader to read from)

proxy: new Ext.data.proxy.Ajax({
type: "ajax",
url: "some url",
reader: {
type: "json",
root: "myRoot"
}
}

Is this intended? The only difference - as far as I can see - is that the setProxy function does not call setModel on the proxy. Although the proxy gets created then.


// Ext.data.AbstractStore

setProxy: function(proxy) {
var me = this;

if (proxy instanceof Ext.data.proxy.Proxy) {
proxy.setModel(me.model); <-------------------------------+
} else { |
if (Ext.isString(proxy)) { |
proxy = { |
type: proxy |
}; |
} |
Ext.applyIf(proxy, { |
model: me.model |
}); |
|
proxy = Ext.createByAlias('proxy.' + proxy.type, proxy); |
// --> Missing proxy.setModel? ----------------------------+
}

me.proxy = proxy;

return me.proxy;
}

mitchellsimoens
31 Jan 2012, 7:36 AM
The proxy should take care of it based on the model property. In the setProxy method this code should do that:


Ext.applyIf(proxy, {
model: me.model
});

nextSTEP
31 Jan 2012, 7:46 AM
Yes you're right, but the problem (or bug?) is that in both cases we have a proxy instance, but not a reader instance.



Ext.applyIf(proxy, {
model: me.model
});

is not equivalent to


proxy.setModel(me.model);

the setModel method also creates the reader instance.

mitchellsimoens
31 Jan 2012, 7:49 AM
Sure it is. In Ext.data.proxy.Proxy you have this:


constructor: function(config) {
config = config || {};

if (config.model === undefined) {
delete config.model;
}

this.mixins.observable.constructor.call(this, config);

if (this.model !== undefined && !(this.model instanceof Ext.data.Model)) {
this.setModel(this.model);
}
}