Results 1 to 7 of 7

Thread: [OPEN EXTJSIV-2541] Stores using implicit models initialized via metaData broken

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha User emblemparade's Avatar
    Join Date
    Nov 2010
    Location
    Chicago, IL
    Posts
    26

    Default [OPEN EXTJSIV-2541] Stores using implicit models initialized via metaData broken

    I'm announcing two bugs (Ext JS 4.0) as well as providing a workaround.

    The first issue is store.add won't work with an implicit model initialized via metaData coming in from the reader, because somehow the implicit model class is not set in the store. My workaround is to override the proxy and have it use a custom 'metaStore' config option.
    Code:
    Ext.define('Fixed.data.proxy.Rest', {
        alias: 'proxy.rest-fixed',
        extend: 'Ext.data.proxy.Rest',
    
        setModel: function(model, setOnStore) {
            this.callParent([model, setOnStore]);
            
            // This is a hack for Ext JS 4.0 to make sure that an implicit model
            // is available for the store to use (otherwise store.add won't work)
            if (setOnStore) {
                this.metaStore.model = model;
            }
        }
    });
    
    Ext.define('Fixed.data.Store', {
        extend: 'Ext.data.Store',
        
        constructor: function(config) {
            config.proxy = Ext.apply({
                type: 'rest-fixed',
                metaStore: this
            }, config.proxy);
    
            this.callParent([config]);
        }
    });
    Use Fixed.data.Store instead of Ext.data.Store. (You can create other proxy types other than REST, too.)

    The second problem is store.remove won't work if your metaData sets an idProperty. The Ext JS code ignores it for your model! Here's the workaround:
    Code:
    Ext.define('Fixed.data.reader.Json', {
        alias: 'reader.json-fixed',
        extend: 'Ext.data.reader.Json',
        
        // This is necessary because Ext JS 4.0 does not create the implicit model correctly
        // (store.remove won't work without a correct idProperty)
        onMetaChange : function(meta) {
            var fields = meta.fields, idProperty = meta.idProperty, newModel;
            
            Ext.apply(this, meta);
            
            if (fields) {
                newModel = {
                    extend: 'Ext.data.Model',
                    fields: fields
                };
                if (idProperty) {
                    newModel.idProperty = idProperty; // This is what was missing from Ext JS 4.0!
                }
                newModel = Ext.define('Fixed.data.ImplicitModel.' + Ext.id(), newModel);
                this.setModel(newModel, true);
            }
            else {
                this.buildExtractors(true);
            }
        }    
    });
    Just use 'json-fixed' for your readers instead of 'json'.

    I hope these issued can be fixed for Ext JS 4.0.1, and am happy if my patches help!

  2. #2
    Ext JS Premium Member
    Join Date
    Feb 2011
    Location
    Sacramento, CA
    Posts
    58

    Default

    When responding to another forum post, I see that this bug post is still active in Ext JS 4.0.2. It also does not have a Jira ticket in the title.

    Can we see about adding this for further review?

    Metadata Configuration Support

  3. #3
    Sencha - Engineering Operations mike.estes's Avatar
    Join Date
    Mar 2011
    Location
    Redwood City, CA
    Posts
    221

    Default

    @emblemparade Thanks for reporting, @CasualNetworks thank you for letting us know this is still present in 4.0.2. Filed as EXTJSIV-2541

  4. #4
    Sencha User
    Join Date
    Apr 2012
    Location
    Austin, Texas
    Posts
    4

    Default

    Not sure about the patch above, but I'm assuming that if responses that included metadata simply reused any existing store/proxy/model configuration and applied meta changes to them if needed (instead of creating an implicit model), that should resolve the issue, yes?

  5. #5
    Ext JS Premium Member
    Join Date
    Feb 2011
    Location
    Sacramento, CA
    Posts
    58

    Default

    Not creating implicit models every request would go miles towards addressing this.

    I would think that the server/metadata might need a reference to which model (or support for nesting), in the case of associated models.

  6. #6
    Sencha User
    Join Date
    Apr 2012
    Location
    Austin, Texas
    Posts
    4

    Default

    Regarding the OP's patches, I've added in the code to set idProperty on the created implicit model if needed, which makes sense.

    I'm still not understanding the first patch though... The current proxy code already sets the passed model onto the store if available, so I don't understand exactly what the issue is or what that patch is supposed to do differently? Perhaps a test case might help.

  7. #7
    Sencha User emblemparade's Avatar
    Join Date
    Nov 2010
    Location
    Chicago, IL
    Posts
    26

    Lightbulb

    I don't have a trivial test case available, because it would require some server-side code.

    But the steps to reproduce:

    1) Create a Ext JS store with no columns. Let the first request to the server contain a flag (a query param?) to tell the server that you want the response to include meta data. For example:

    Code:
            autoSync: true,
            autoLoad: {
                params: {
                    start: 0,
                    meta: true // flag for the server
                }
            }
    2) The server's JSON response would include metadata, something like this:

    Code:
            "metaData": {
                        "root": "documents",
                        "totalProperty": "count",
                        "idProperty": "id",
                        "fields": [ ... ]
            }
    This will cause the store to create an implicit model to match the "fields". Unfortunately, without my fix, this implicit model will not behave well for the full set of store operations. store.add, for example, will break.

Similar Threads

  1. Read-only Models & Stores?
    By wizkid in forum Ext: Discussion
    Replies: 1
    Last Post: 22 Mar 2011, 4:02 AM
  2. [FIXED]Models and Stores
    By sg707 in forum Ext:Bugs
    Replies: 5
    Last Post: 20 Feb 2011, 3:50 AM
  3. Stores and Models
    By dombroskib in forum Sencha Touch 1.x: Discussion
    Replies: 14
    Last Post: 6 Jan 2011, 12:44 PM
  4. Questions on Models/Stores and primary and foreign keys
    By jeronimo in forum Sencha Touch 1.x: Discussion
    Replies: 1
    Last Post: 22 Aug 2010, 5:59 PM
  5. Questions about Models, Stores, and dynamic Lists
    By jonathanstark in forum Sencha Touch 1.x: Discussion
    Replies: 2
    Last Post: 10 Aug 2010, 8:54 AM

Posting Permissions

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