Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Cannot subclass a Model properly

    Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJS-13006 in 5.0.0b3.
  1. #1
    Sencha Premium User mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    3,147
    Vote Rating
    201
      1  

    Default Cannot subclass a Model properly

    Code:
    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

  2. #2
    Sencha Premium User
    Join Date
    Mar 2007
    Location
    Norway
    Posts
    197
    Vote Rating
    5
      0  

    Default

    Why would you want to subclass something with the same name?
    Founder of the Path of Exticism

  3. #3
    Sencha Premium User mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    3,147
    Vote Rating
    201
      0  

    Default

    So, you say "Resource" === "Sch.model.Resource"?

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

  4. #4
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,380
    Vote Rating
    1524
      0  

    Default

    Thanks for the report! I have opened a bug in our bug tracker.

  5. #5
    Sencha User dongryphon's Avatar
    Join Date
    Jul 2009
    Location
    Kansas
    Posts
    1,748
    Vote Rating
    263
      0  

    Default

    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:

    Code:
    Ext.define('Sch.model.ResourceUser', {
        fields: [{
            name: 'resourceId',
            reference: 'Resource'  // <---
        }]
    });
    This appears in the older association syntax as well. So we either had to:

    1. Always require full classnames
    2. Guess
    3. Generate an error


    What does work, would be this:

    Code:
    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:

    Code:
    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.
    Don Griffin

    "Use the source, Luke!"

  6. #6
    Sencha Premium User mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    3,147
    Vote Rating
    201
      0  

    Default

    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?

    Code:
    Ext.define('Sch.model.Resource', {
        extend : 'Ext.data.Model'
    })
    
    Ext.define('Gnt.model.Resource', {
        extend : 'Sch.model.Resource'
    });
    This does not fix it:

    Code:
    Ext.define('Gnt.model.Resource', {
        extend      : 'Sch.model.Resource',
    
        schema: {
            namespace: 'Gnt.model'
        }
    })

  7. #7
    Sencha Premium User
    Join Date
    Mar 2007
    Location
    Norway
    Posts
    197
    Vote Rating
    5
      0  

    Default

    Quote Originally Posted by mankz View Post
    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.
    Founder of the Path of Exticism

  8. #8
    Sencha User SamuraiJack1's Avatar
    Join Date
    May 2008
    Posts
    574
    Vote Rating
    7
      0  

    Default

    This scenario should definitely just work.

    Code:
    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.

  9. #9
    Sencha Premium User
    Join Date
    Jan 2013
    Posts
    62
    Vote Rating
    4
      0  

    Default

    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.

    Code:
    Ext.define('QLP.model.common.sales.Representative', {
        extend      : 'Ext.data.Model',
        
        fields      : [
            {name: 'first_name',        type: 'string'}
        ]
    })
    Code:
    Ext.define('LDB.model.sales.Representative', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'po_name',                    type: 'string'}
        ]
    })
    HTML Code:
    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

  10. #10
    Ext JS Premium Member
    Join Date
    Jul 2011
    Location
    Atlanta
    Posts
    39
    Vote Rating
    7
      0  

    Default

    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.

    Code:
    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'
    });
    Last edited by Carun; 9 Apr 2014 at 5:18 AM. Reason: fixed code formatting

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •