Results 1 to 3 of 3

Thread: Feature request: support multiple schema proxy templates for unrelated models

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha Premium Member
    Join Date
    Jan 2014
    Posts
    203

    Default Feature request: support multiple schema proxy templates for unrelated models

    [EDIT]
    Altered request (after evants reply):
    Describe schema.id property in the docs which allows differentiation between schemas.
    [/EDIT]


    A nice feature has been introduced in ExtJS5 to shortcut model definitions by using a template definition for proxies in Models in the schema attribute
    Code:
    Ext.define('Fiddle.model.Base', {
                extend: 'Ext.data.Model',
                schema: {
                    namespace: 'Fiddle.model',
                    proxy: {
                        url: '/api/{entityName:uncapitalize}'
                    }
                }
    });
    With this inheriting models don't have to define an explicite proxy.

    However it appears there is a over-restrictive limitation with this feature: AFAIK there can be only one schema proxy template in an application, given that applications may use two or more different data sources which require requests at different endpoints.

    Consider this small example (link to Fiddle)
    Code:
    Ext.application({
         name : 'Fiddle',
    
        // 1. check out the base models for Apples and Oranges below
        // 2. run the example and check the console output
        launch : function() {
            /**
             * base class for entities from the apple DB in the application.
             * defines how data should be fetched from the proxy for inheriting models.
             */
            Ext.define('Fiddle.model.apple.BaseApple', {
                extend: 'Ext.data.Model',
                /**
                 * Defines an `{@link Ext.data.schema.Schema}`
                 */
                schema: {
                    namespace: 'Fiddle.model.apples',
                    proxy: {
                        url: '/api/apple/{entityName:uncapitalize}'
                    }
                }
            });
    
            /**
             * base class for entities from the orange DB in the application.
             * defines how data should be fetched from the proxy for inheriting models.
             */
            Ext.define('Fiddle.model.oranges.BaseOrange', {
                extend: 'Ext.data.Model',
                /**
                 * Defines an `{@link Ext.data.schema.Schema}`
                 */
                schema: {
                    namespace: 'Fiddle.model.oranges',
                    proxy: {
                        url: '/api/orange/{entityName:uncapitalize}'
                    }
                }
            });
    
            Ext.Msg.alert('Fiddle', 'Welcome to Sencha Fiddle!');
        }
    });
    When running this it results in the following console error
    Code:
    [E] The schema can only be reconfigured once                (ext-all-debug.js:5677)
    [...]
    Uncaught Error: The schema can only be reconfigured once   (ext-all-debug.js:1610)

    Feature requests
    1. Mention this restriction in the docs e.g. here
    2. Lessen this restriction so that it only applies to inheriting models of a model which defined such a proxy template; i.e. allow several schema proxy templates within an application if models who declare them are not in the same inheritance chain

  2. #2
    Sencha Premium User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    You need to give them an id, otherwise it thinks you're talking about the global schema.

    Code:
    Ext.application({
        name : 'Fiddle',
    
        // 1. check out the base models for Apples and Oranges below
        // 2. run the example and check the console output
        launch : function() {
            /**
             * This class is the base class for entities from the apple DB in the application.
             * Above all it defines how data should be fetched from the proxy for inheriting models.
             */
            Ext.define('Fiddle.model.apple.BaseApple', {
                extend: 'Ext.data.Model',
                /**
                 * Defines an `{@link Ext.data.schema.Schema}`
                 */
                schema: {
                    id: 'apples',
                    namespace: 'Fiddle.model.apples',
                    proxy: {
                        url: '/api/apple/{entityName:uncapitalize}'
                    }
                }
            });
    
            /**
             * This class is the base class for entities from the orange DB in the application.
             * Above all it defines how data should be fetched from the proxy for inheriting models.
             */
            Ext.define('Fiddle.model.oranges.BaseOrange', {
                extend: 'Ext.data.Model',
                /**
                 * Defines an `{@link Ext.data.schema.Schema}`
                 */
                schema: {
                    id: 'oranges',
                    namespace: 'Fiddle.model.oranges',
                    proxy: {
                        url: '/api/orange/{entityName:uncapitalize}'
                    }
                }
            });
    
            Ext.Msg.alert('Fiddle', 'Welcome to Sencha Fiddle!');
        }
    });

  3. #3
    Sencha Premium Member
    Join Date
    Jan 2014
    Posts
    203

    Default

    Thanks @evant
    That's what I was looking for; I was aware that there was a default schema (and this might be the root of the problem), but not how to differentiate between schemas.
    But I haven't seen that id property anywhere in the docs (?). At least not in the description for Model.schema or Schema itself.
    => IMO this id property needs to be described in the docs.
    However the second feature request is thus irrelevant.

Posting Permissions

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