0
votes

I'm using Sencha Touch 2.4, with Sencha Cmd 6.1.x (so I believe I'm using Ext JS 6). I've got the following model and store:

Ext.define('App.model.User', {
extend: 'Ext.data.Model',

fields: [{
    name: 'organizationId',
    type :'int',
    reference: {
        type: 'Organization',
        association: 'UsersByOrganization',
        role: 'organization',
        inverse: 'users'
    }
}, {
    "name": "matricola",
    "type": "int"
}]

});

and

 Ext.define('App.model.Organization', {
 extend: 'Ext.data.Model',
 fields: ['name']

});

I load my stores (with a 'sql' proxy) using the usual way, but I cannot find my reference anywhere. I simply get the records and I cannot call "users" or its inverse.

Any idea?

2

2 Answers

0
votes

Sencha Touch 2.4 and ExtJS 6 are two different toolkits. Syntax for creating models and stores are similar in both, but not in all cases.

I believe what you are looking for is the StoreManager. If you have defined a store like so:

Ext.define('App.store.User', {
   extend: 'Ext.data.Store',
   storeId: 'User',
   model: 'User'
});

Then you can reference the store like so:

 // Return a list of users
 Ext.getStore('User').getRange();
0
votes

The code below works for me on Ext JS 6. Maybe you can model yours after this example:

Ext.define('App.model.Customer', {
    extend: 'Ext.data.Model',
    idProperty: 'customerNumber',
    fields: [
        { name: 'customerNumber', type: 'int' },
        { name: 'customerName', type: 'string' },
        { name: 'contactLastName', type: 'string' },
        { name: 'contactFirstName', type: 'string' }
    ],
    proxy: {            
        type: 'ajax',
        url: '../../../api/CustomersAssociationsReference',
        reader: {
            type: 'json',
            rootProperty: 'customers',
            totalProperty: 'count'
        }
    }
});

Ext.define('App.model.Order', {
    extend: 'Ext.data.Model',
    idProperty: 'orderNumber',
    fields: [
        { name: 'orderNumber', type: 'int' },
        {
            name: 'customerNumber', reference: {
                type: 'App.model.Customer',
                inverse: 'orders'           
            }
        },
        { name: 'orderDate', type: 'string' },
        { name: 'status', type: 'string' }
    ],
    proxy: {        // Note that proxy is defined in the Model, not the Store
        type: 'ajax',
        url: '../../../api/OrdersAssociationsReference',
        reader: {
            type: 'json',
            rootProperty: 'orders',
            totalProperty: 'count'
        }
    }
});

Ext.application({
    name: 'App',
    models: ['Customer', 'Order'],
    stores: ['Customers', 'Orders'],
    launch: function () {

        var customersStore = Ext.getStore('Customers');
        customersStore.load(function (records, operation, success) {

            var customer = records[0],
                orders = customer.orders(),
                order;
            orders.load(function (records, operation, success) {
                console.log('Orders for ' + customer.get('customerName') + ':\n-------------------------------------------------------');
                for (i = 0, len = records.length; i < len; i++) {
                    order = records[i];
                    console.log('orderNumber: ' + order.get('orderNumber'));
                    console.log('orderDate: ' + order.get('orderDate'));
                    console.log('status: ' + order.get('status'));
                    console.log('-------------------------------');
                }
            })
        });
    }
});