Results 1 to 5 of 5

Thread: Store load marks all as phantom/new

  1. #1

    Join Date
    Sep 2010
    Location
    Nashville, TN
    Posts
    58

    Default Answered: Store load marks all as phantom/new

    In 2.0.1, once a store is initially loaded, all records are flagged as phantom / new. When you try to sync that store later with an actual addition or update, all records are passed as data. I'm not sure I see the logic behind this and would assume that when the store is initially loaded (from the server in this case), no records would be "new" as they are all existing.

    I want to update the server with additions/update/delete, but would rather not continuously pass the entire data set each time this occurs. I've tried several ways of doing this, but here is where it sits now:

    Code:
            form = button.up().up();
            record = form.getRecord();
            values = form.getValues();
            var store = Ext.getCmp('bnamelist').getStore();
            var newRecord = Ext.create('BBAdmin.model.bModel');
            newRecord.setConvertedData(form.getValues());
            var errors = newRecord.validate();
            if (values.b_id > 0) {
                //Update
                record.set(values);
            } else {
                store.add(newRecord);
            }
            store.sync();
    I realize that the best practices are changing rapidly with the ST rework (which is good), but I'm struggling to filter through the 3 or more posted ways of doing a data add. Should I tie the proxy to the model rather than the store? Thanks.

  2. From the looks of it you may want to add the idProperty in your model's config

    Code:
    idProperty : 'glossary_id'

  3. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,448
    Answers
    3997

    Default

    I would try it with 2.0.1.1 which was a patch fix for some data issues. After that are you specifying the id value at all? If not then it will probably be marked as phantom
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  4. #3

    Join Date
    Sep 2010
    Location
    Nashville, TN
    Posts
    58

    Default

    I've tried this with 2.0.1.1 and get the same results. Are you asking if I reference each record by id? If so, no I do not, I just load it via Direct.

    Since it is happening on all stores, I'll include one example with model.
    Code:
    Ext.define('BBAdmin.model.glossaryModel', {
        extend: 'Ext.data.Model',
        config: {
            fields: [
                {
                    name: 'glossary_id',
                    type: 'int'
                },
                {
                    name: 'gtitle',
                    type: 'string'
                },
                {
                    name: 'gbody',
                    type: 'string'
                },
                {
                    name: 'gkey',
                    type: 'string'
                }
            ]
        }
    });
    Code:
    Ext.define('BBAdmin.store.glossaryDirect', {
        extend: 'Ext.data.Store',
        requires: [
            'BBAdmin.model.glossaryModel'
        ],
    
    
        config: {
            autoLoad: true,
            model: 'BBAdmin.model.glossaryModel',
            storeId: 'glossaryDirect',
            proxy: {
                type: 'direct',
                directFn: glossaryDirect.getAllGrid,
                reader: {
                    type: 'json',
                    rootProperty: 'data'
                }
            },
            sorters: {
                property: 'gtitle'
            }
        }
    });



    Code:
      Ext.Viewport.setMasked({
                xtype:'loadmask',
                indicator: true,
                message:'Submitting...'
            });
            form = button.up().up();
            record = form.getRecord();
            values = form.getValues();
            //todo validation
            var store = Ext.getStore('glossaryCRUD');
    
    
            var newRecord = Ext.create('BBAdmin.model.glossaryModel');
            newRecord.setConvertedData(form.getValues());
            var errors = newRecord.validate();
    
    
            if (!errors.isValid()) {
                Ext.Msg.alert('Wait!', errors.getByField("gtitle")[0].getMessage(), Ext.emptyFn);
                newRecord.reject();
                newRecord.destroy();
                Ext.Viewport.setMasked(false);
                return;
            } else {
                store.add(newRecord);
                debugger;
                store.sync();
    
    
                Ext.Viewport.setMasked(false);
                Ext.getStore('glossaryCRUD').removeAll();
                Ext.getCmp('glossarylist').getStore().load();
                Ext.getCmp('pnavtab').pop();
                this.currentGlossary = '';
            }
    I've ended up creating a CRUDStore for the sole purpose of CUD. Obviously not the way I want to do this, but I needed to get this out the door. What is strange is from the first point I can get a handle on the store after the load, it references all the records as dirty. No action other than the load performed on the store. Thanks again for looking into this.

  5. #4
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,448
    Answers
    3997

    Default

    From the looks of it you may want to add the idProperty in your model's config

    Code:
    idProperty : 'glossary_id'
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  6. #5

    Join Date
    Sep 2010
    Location
    Nashville, TN
    Posts
    58

    Default

    Thank you very much for pointing this out.

Posting Permissions

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