extjssencha-touch-2sencha-touch-2.2

sencha touch nested 'hasMany' associations


Scenario

Lets go classic User hasMany Order hasMany Productos.

1.- Create and load a UserStore

2.- Get first record

3.- This record has a ordersStore (auto-generated, so far as expected)

4.- Then get first record of ordersStore, look for productosStore BUT THERE IS NONE although a look to raw config shows array products.

So my question is: ARE SECOND LEVEL HASMANY ASSOCIATIONS GENERATING A STORE AUTOMATICALLY IN THE MODEL THAT THE ASSOCIATION IS DEFINED ?

any known issues for Sencha Touch 2.2.1 regarding this?

Dummy demo code:

Ext.define('Myapp.model.User', {
    extend  : 'Ext.data.Model',
    config : {
        fields       : [
            {
                name : 'name',
                type : 'string'
            }
        ],
        hasMany : [
            {
                model   : 'Myapp.model.Order',
                name    : 'orders',
                associationsKey : 'orders'
            }
        ]
    }
});

Ext.define('Myapp.model.Order', {
    extend  : 'Ext.data.Model',
    config : {
        fields       : [
            {
                name : 'orderName',
                type : 'string'
            }
        ],
        hasMany : [
            {
                model   : 'Myapp.model.Product',
                name    : 'products',
                associationsKey : 'products'
            }
        ]
    }
});

Ext.define('Myapp.model.Product', {
    extend  : 'Ext.data.Model',
    config : {
        fields       : [
            {
                name : 'productName',
                type : 'string'
            }
        ]
    }
});

enter image description here


Solution

  • hasMany : [
                {
                    model   : 'Myapp.model.Product',
                    name    : 'products',
                    associationsKey : 'products',
                    autoLoad : true  // < -----------THIS ONE MAKED IT
                }
            ]
    

    thanks @_ErnestoR