View Full Version : Extending Model Not Working

21 Oct 2011, 12:24 AM

I've encountered the following bug in ExtJS 4.0.2a. I believe it's with the JSON Reader class.

I have a Model [A] that has fields, a proxy, and a "hasMany" property.
I have another Model that "extend"s [A]. It only has a proxy override in it, not that it seems to matter.

Using Model [B] works fine in the application.
However, as soon as I try to load a store with instances of Model [A], I get the following error:

me.buildExtractors() is not a function
It's at line 37318 in the ExtJS debug file, and the failing function in ExtJS looks like this:

* Creates new Reader.
* @param {Object} config (optional) Config object.
constructor: function(config) {
var me = this;

Ext.apply(me, config || {});
me.fieldCount = 0;
me.model = Ext.ModelManager.getModel(config.model);
if (me.model) {
[B] me.buildExtractors();

If I comment-out Model [B], the functionality that uses Model [A] suddenly works again, even though they never ever touch Model [B].

Is there a workaround for this?

Thanks very much...

21 Oct 2011, 12:30 AM
Have a look at this (http://www.sencha.com/forum/showthread.php?134650-Extending-model-perturbs-associations-(4.0.1)). It might be related.

21 Oct 2011, 1:16 AM
It was related, and it fixed it for me!

Thank you very much!

21 Oct 2011, 1:19 AM
Oops, sorry, no it doesn't =(

Same error when loading instances of Model [A] into a store.

Some more information:

Model [A] hasMany of Model [C]
Model [B] extends Model [A]

When loading a store with Model [A], it fails to create the Reader for Model [C] according to the debugger.

21 Oct 2011, 1:42 AM
That would have been just too much luck !
You might need to see how models are set for proxies and readers then and use a similar trick as the one provided (e.g. copy model with Ext.apply({}, model).

Would be interested to see your solution, and very interested to see this type of bugs fixed in the code base.

Good luck,

23 Oct 2011, 10:15 AM
Thanks, I'll certainly give it a go... I think I lack the Javascript knowledge to fix it properly, but a quick look through the debugger to understand what's going on shouldn't hurt. Still, if anyone knows the fix, I'd love to know about it so I can move on with the rest of my tasks =)

23 Oct 2011, 11:10 AM
I have this override somewhere in a Proxy class that I used in my app, and the reason why it is there might - again - be related to the model extension problem . You might give it a try, but without guarantee...

constructor: function () {
//make sure the model (and reader ar initiated
if(this.model !== undefined && !(this.reader instanceof Ext.data.Reader)) {this.setModel(this.model)}