1. #1
    Sencha Premium Member
    Join Date
    Mar 2011
    Posts
    10
    Vote Rating
    0
    Dehru is on a distinguished road

      0  

    Default Model Associations Return Empty Stores

    Model Associations Return Empty Stores


    Hello,
    I'm trying to use the generated association functions as described in the data guide to traverse associations in my model. For instance, a workspace has many portlets. When I define these two models and a store, and then I try to use workspace.portlets() I don't get any of the portlets. But if I walk the data field I see the data. Please see my example below and the console.log statements.

    Code:
            Ext.define('Workspace', {
                extend: 'Ext.data.Model',
                fields: [
                    'id','name'
                ],
                hasMany : {model:'Portlet', name:'portlets'}
            });
    
    
            Ext.define('Portlet', {
                extend: 'Ext.data.Model',
                fields: [
                    'id', 'workspace_id', 'name', 'column'
                ],
                belongsTo : 'Workspace'
            });
    
    
            Ext.onReady(function() {
    
                var portletStore = new Ext.data.Store({
                    storeId: 'portletStore',
                    model: 'Workspace',
                    data: [
                        {
                            "id":1,
                            "name": 'hello workspace',
                            "portlets": [
    
                                {
                                    "id":1
                                    ,"workspace_id":1
                                    ,"title": "One"
                                    ,"column": 1
                                    ,"xtype": "chartportlet"
                                }
                                ,
                                {
                                    "id":2
                                    ,"workspace_id":1
                                    ,"title": "Two"
                                    ,"column" : 2
                                    ,"xtype": "gridportlet"
                                }
                            ]
                        }
                    ]
                    
                });
    
                console.log(portletStore.first());//Works and data property shows two child portlets
                console.log(portletStore.first().portlets());//Does not contain any child portlets
                console.log(portletStore.first().data.portlets);//Does contain child portlets
                console.log(portletStore.first().getAssociatedData());//empty
            });
    I must be building the relationship wrong but I can't see why. Any help would be appreciated.

  2. #2
    Sencha User
    Join Date
    Jul 2007
    Location
    Sydney Australia
    Posts
    7
    Vote Rating
    3
    jamesmoey is on a distinguished road

      0  

    Default


    You need to specify the store proxy type.

    Code:
        proxy: {
          type: 'memory',
          reader: {
            type: 'json'
          }
        },
    Part of your sample code will become
    Code:
      var portletStore = new Ext.data.Store({
        storeId: 'portletStore',
        model: 'Workspace',
        proxy: {
          type: 'memory',
          reader: {
            type: 'json'
          }
        },
        data: [
          {
            "id":1,
            "name": 'hello workspace',
            "portlets": [
    
              {
                "id":1
                ,"workspace_id":1
                ,"title": "One"
                ,"column": 1
                ,"xtype": "chartportlet"
              }
              ,
              {
                "id":2
                ,"workspace_id":1
                ,"title": "Two"
                ,"column" : 2
                ,"xtype": "gridportlet"
              }
            ]
          }
        ]
      });
    Hope this help.

  3. #3
    Sencha Premium Member
    Join Date
    Mar 2011
    Posts
    10
    Vote Rating
    0
    Dehru is on a distinguished road

      0  

    Default Thanks

    Thanks


    I'll give that a shot.

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi