Take a look at this JSON structure
{
"id": 123,
"name": "Ed",
"orders": [
{
"id": 50,
"total": 100,
"order_items": [
{
"id": 20,
"price": 40,
"quantity": 2,
"product": {
"id": 1000,
"name": "MacBook Pro"
}
},
{
"id": 21,
"price": 20,
"quantity": 3,
"product": {
"id": 1001,
"name": "iPhone"
}
}
]
}
]
}
These are my defined models
Ext.define("User", {
extend: 'Ext.data.Model',
fields: [
'id', 'name'
],
hasMany: {model: 'Order', name: 'orders', associationKey: 'orders'}
});
Ext.define("Order", {
extend: 'Ext.data.Model',
fields: [
'id', 'total'
],
hasMany : {model: 'OrderItem', name: 'orderItems', associationKey: 'order_items'}
});
Ext.define("OrderItem", {
extend: 'Ext.data.Model',
fields: [
'id', 'price', 'quantity'
],
hasOne : {
model: 'Product',
name: 'product',
associationKey: 'product'
}
});
Ext.define("Product", {
extend: 'Ext.data.Model',
fields: [
'id', 'name'
]
});
Upon loading the data into my store and inspecting the store record, I encounter this issue
https://i.sstatic.net/3jHOM.png
The Orders and related data are not being retrieved. Something seems amiss with the model definitions, but I'm unable to pinpoint the problem. Thanks for your help in advance.
Update Here's how my store is configured and the data is loaded
Ext.define('Company.store.TestOrders', {
extend: 'Ext.data.Store',
alias: 'store.testorders',
model: 'User',
data:[
{
"id": 123,
"name": "Ed",
"orders": [
{
"id": 50,
"total": 100,
"order_items": [
{
"id": 20,
"price": 40,
"quantity": 2,
"product": {
"id": 1000,
"name": "MacBook Pro"
}
},
{
"id": 21,
"price": 20,
"quantity": 3,
"product": {
"id": 1001,
"name": "iPhone"
}
}
]
}
]
}],
storeId: 'TestOrders',
proxy: {
type: 'memory'
}
});
Later on, I retrieve the data using the following method
Ext.getStores('TestOrders').getAt(0);