PDA

View Full Version : [FIXED] Cannot subclass a Model properly



mankz
4 Apr 2014, 1:42 AM
Ext.define('Sch.model.Resource', {
extend : 'Ext.data.Model'
})

Ext.define('Resource', {
extend : 'Sch.model.Resource'
});


Crash boom bang.


[E] Ext.data.schema.Schema.addEntity(): Duplicate entity name "Resource": Sch.model.Resource and Resource

bone
4 Apr 2014, 2:24 AM
Why would you want to subclass something with the same name?

mankz
4 Apr 2014, 3:17 AM
So, you say "Resource" === "Sch.model.Resource"?

Beg to differ. I like to pick unique class names freely.

mitchellsimoens
4 Apr 2014, 3:51 AM
Thanks for the report! I have opened a bug in our bug tracker.

dongryphon
4 Apr 2014, 2:46 PM
Fun one.

The reason this is more picky is because of the way we define associations. This declaration creates either an ambiguity, extra verbosity or an undesired linkage:



Ext.define('Sch.model.ResourceUser', {
fields: [{
name: 'resourceId',
reference: 'Resource' // <---
}]
});


This appears in the older association syntax as well. So we either had to:


Always require full classnames
Guess
Generate an error


What does work, would be this:



Ext.define('Sch.model.Resource', {
extend : 'Ext.data.Model'
})

Ext.define('Sch.model.sub.Resource', {
extend : 'Sch.model.Resource'
});


(Well it will in the next beta :) )

Since you are providing models as bases for customers who then build apps... Something like this should work but probably has timing issues at present:



Ext.define('Sch.model.Resource', {
extend : 'Ext.data.Model'
})

Ext.define('App.model.Resource', {
extend : 'Sch.model.Resource',

schema: {
namespace: 'App.model'
}
});


What that should do (give or taking timing) is enable short names to resolve in the "App.model" namespace and still reference outsiders by full classname.

Using a model in the global namespace would also work in the same (not-quite-yet) way... give or take matters of taste. :)

mankz
7 Apr 2014, 9:51 AM
We don't use associations at all and likely never will. Our extension looks like this - a default Resource defined by the Scheduler package which is then extended in the Gantt package. This prevents our Gantt from working in any way. Will this be fixed, or do we have to rename our classes even though we don't care about associations?

If it won't be 'fixed', this is a breaking change and should be documented properly (and we'll need to do a breaking change to workaround it - rename our Gnt.model.Resource and instruct any Bryntum clients to do the same). Thoughts?


Ext.define('Sch.model.Resource', {
extend : 'Ext.data.Model'
})

Ext.define('Gnt.model.Resource', {
extend : 'Sch.model.Resource'
});

This does not fix it:


Ext.define('Gnt.model.Resource', {
extend : 'Sch.model.Resource',

schema: {
namespace: 'Gnt.model'
}
})

bone
7 Apr 2014, 2:54 PM
So, you say "Resource" === "Sch.model.Resource"?

Beg to differ. I like to pick unique class names freely.

console.log("Resources" === "Sch.model.Resource");

No. I can't really say they are identical, can I?

I'm just asking -why- you would do something like that. Personally I see nothing but confusion and, alas, errors ;)

Just curious, I'm not saying you are wrong.

(For the record I believe a hell of a lot more problems like this will appear now that everything is being "stringreferenced")

EDIT: Too late for scandis.
EDIT2: Later still.

SamuraiJack1
7 Apr 2014, 11:43 PM
This scenario should definitely just work.


Ext.define('Sch.model.Resource', {
extend : 'Ext.data.Model'
})

Ext.define('Resource', {
extend : 'Sch.model.Resource'
});

Using full class names is the answer. The shorthand reference can still be used, as long as its unique.

Dev@QLP
8 Apr 2014, 1:35 PM
So, I'm confused. I'm running into this error now as well. I figured this would have been fine since they are in seperate namespaces. They don't even subclass each other.



Ext.define('QLP.model.common.sales.Representative', {
extend : 'Ext.data.Model',

fields : [
{name: 'first_name', type: 'string'}
]
})




Ext.define('LDB.model.sales.Representative', {
extend: 'Ext.data.Model',
fields: [
{name: 'po_name', type: 'string'}
]
})




Ext.data.schema.Schema.addEntity(): Duplicate entity name "Representative": QLP.model.common.sales.Representative and LDB.model.sales.Representative ext-all-debug.js:5600
Object ext-all-debug.js:5606
console.trace() ext-all-debug.js:5612
Uncaught Error: Duplicate entity name "Representative": QLP.model.common.sales.Representative and LDB.model.sales.Representative

Carun
8 Apr 2014, 8:25 PM
I got away by creating a separate Schema per namespace. In my case, each transaction is in a different namespace and have many models that have the same class name (entity name) across namespaces. So I went about creating a Schema for each namespace, and a Base model that attaches to this schema. All other models in that namespace inherit from the Base model.



Ext.define('Example.hr.employee.Schema', {
extend : 'Ext.data.schema.Schema',
alias : 'schema.hr.employee',
namespace: 'Example.hr.employee.model'
});

Ext.define('Example.hr.employee.model.Base', {
extend : 'Ext.data.Model',
schema : 'hr.employee'
});

dongryphon
8 Apr 2014, 10:52 PM
We are definitely looking at solutions on this (some are already merged but more are likely needed). The current heuristic for picking the entityName (the conflicting config) is overly simplistic.

dfrederick
16 Apr 2014, 12:37 PM
Is there any update for this or an ETA? I upgraded to 5.0.0.736 today, but it's still an issue. We're dead in the water with this too until a fix comes out.

Zdeno
2 Jun 2014, 3:38 AM
Fixed in latest version you can download trough support portal.