一个模型中有多个hasMany关联

时间:2013-12-19 10:59:27

标签: json sencha-touch-2 associations has-many

我有以下JSON结构:

{
                orderId : '00410',
                name : 'Zuiger',
                productionQuantity : '4',
                materials : [
                    {
                      materialId    : 'ALU.BALK.10X70',
                      description   : 'Aluminium balk 10 x 70',
                      quantityPP    : '70mm',
                      totalQuantity : '0.4'
                    },
                    {
                      materialId    : 'ALU.BALK.10X70',
                      description   : 'Aluminium balk 10 x 70',
                      quantityPP    : '70mm',
                      totalQuantity : '0.4'
                    }],
                operations : [
                    {
                      operationId   : 'ZAGEN',
                      lineNr        : '10',
                      description   : 'Zagen groot',
                      started   : false
                    }, 
                    {
                      operationId   : 'FR003',
                      lineNr        : '20',
                      description   : 'Frezen Heidenhein',
                      started   : true
                    }] 
            }

所以我有一个订单,其中包含材料清单和/或操作清单。此JSON当前位于使用Data标记的Store文件中,并且是自动加载的。这是出于测试目的。

用于此的模型是Order,它包含2个与材料和操作有关的多个关联:

Ext.define('wp-touch.model.Order', {
extend: 'Ext.data.Model',

requires: [ 
           'wp-touch.model.Material', 
           'wp-touch.model.Operation'
           ],

config: {
    idProperty: 'Id',       
    fields: [
            { name: 'orderId',  type: 'string'},
            { name: 'name',     type: 'string'},        
            { name: 'productionQuantity', type: 'string'},
    ],
    associations: [
              { 
                type: 'hasMany',
                associationKey: 'materials',
                model: 'wp-touch.model.Material',
                name: 'material',
                primairyKey: 'materialId',
                foreignKey: 'orderId'
              },
              { 
                type: 'hasMany',
                associationKey: 'operations',
                model: 'wp-touch.model.Operation', 
                name: 'operation',
                primairyKey: 'operationId',
                foreignKey: 'orderId'
              }   
    ],

}});

当商店加载时,它只加载第一个hasMany。当我在JSON消息中清空材料数组时,它在操作中加载就好了。所以它似乎只加载了一个hasMany关联。有什么方法可以解决这个问题吗?

以下是材料和操作模型;

Ext.define('wp-touch.model.Material', {
extend: 'Ext.data.Model',

config: {
    idProperty: 'Id',

    fields: [
            { name: 'materialId',   type: 'string'},
            { name: 'description',  type: 'string'},
            { name: 'quantityPP',   type: 'string'},
            { name: 'totalQuantity',type: 'string'},
            { name: 'orderId',      type: 'string'}
    ],
    belongsTo: [
                { 
                    model: 'wp-touch.model.Order',
                    name: 'order',
                    primairyKey: 'materialId',
                    foreignKey: 'orderId' 
                }
    ]
}});

Ext.define('wp-touch.model.Operation', {
extend: 'Ext.data.Model',

config: {
    idProperty: 'Id',

    fields: [
            { name: 'operationId',  type: 'string'},
            { name: 'lineNr',       type: 'int'},       
            { name: 'description',  type: 'string'},
            { name: 'started',      type: 'boolean'},
            { name: 'orderId',      type: 'string'}
    ],
    belongsTo: [
                { 
                    model: 'wp-touch.model.Order', 
                    name: 'order',
                    primairyKey: 'operationId',
                    foreignKey: 'orderId' 
                }
    ]
}});

0 个答案:

没有答案