1. #1
    Sencha User
    Join Date
    Nov 2013
    Posts
    51
    Vote Rating
    1
    MonkeySleeve is on a distinguished road

      0  

    Default [Solved] Load multiple hasMany not possible?

    [Solved] Load multiple hasMany not possible?


    I have this store which has Data in it:
    Code:
    Ext.define('app.store.OrderStore', {    extend:    'Ext.data.Store',
        
        
        config: {
            model:    'app.model.Order',
            storeId: 'OrderStore',
            autoLoad: true,
            
            data : [
                    {
                        orderId : '00410',
                        name : 'Piston',
                        productionQuantity : '4',
                        materials : [
                            {
                              materialId    : 'ALU.BAR.10X70',
                              description    : 'Aluminium bar 10 x 70',
                              quantityPP    : '70mm',
                              totalQuantity    : '0.4m'
                            }],
                        operations : [
                            {
                              operationId     : 'SAW',
                              lineNr        : '10',
                              description    : 'Sawing big',
                              started    : false
                            }] 
                    }
                ],
        }
    });
    And this is the Order model which has two hasMany item(Material and Operation):
    Code:
    Ext.define('app.model.Order', {    extend:    'Ext.data.Model',
        
        config: {
            idProperty: 'Id',
            
            fields: [
                    { name: 'orderId',    type: 'string'},
                    { name: 'name',          type: 'string'},        
                    { name: 'productionQuantity', type: 'string'},
            ],
            hasMany: [
                      { 
                        associationKey: 'operations',
                        model: 'app.model.Operation', 
                        name: 'operation'
                      },
                      { 
                        associationKey: 'materials',
                        model: 'app.model.Material',
                        name: 'material'
                      }
            ]
        }
    });
    For some reason when the Store is loaded it only loads in the materials into the material array. The operation array is always empty. When i switch the two hasMany items, it loads in the operations but not the materials. So it only seems to be loading in the properties of one the two.

    Here are the Material and Operation models:
    Code:
    Ext.define('app.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: 'app.model.Order',
                            foreignKey: 'orderId'
                        }
            ]
        }
    });
    Code:
    Ext.define('app.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: 'app.model.Order', 
                            foreignKey: 'orderId' 
                        }
            ]
        }
    });
    Edit: Ok after some testing it doesn't seem to switch between the two. It's only loading in Operations. And it seems that the first item of the operation array contains an Order object which is it's parent. Why is this?

  2. #2
    Sencha User
    Join Date
    Nov 2013
    Posts
    51
    Vote Rating
    1
    MonkeySleeve is on a distinguished road

      0  

    Default [Solved] Load multiple hasMany not possible?

    [Solved] Load multiple hasMany not possible?


    Ok so i added a extra attribute in my JSON and created an extra model named OrderList which has a hasMany associations with Order. Now when i load this in i can see in my console.log when the store is loaded that it actually loads in all the materials and operations.When i remove this however i'm back where i started and it only loads in materials or operations. In the console.log i can see that it creates two stores as a class: materialStore and operationStore. These stores actually loaded in all the data from the JSON. So why isn't it loaded into my models?

  3. #3
    Sencha - Support Team
    Join Date
    Oct 2011
    Posts
    2,954
    Vote Rating
    90
    fmoseley is just really nice fmoseley is just really nice fmoseley is just really nice fmoseley is just really nice fmoseley is just really nice

      1  

    Default


    It should be. I was able to get it to work in the following modified version of your code using Touch 2.3.1
    I changed the idProperty on your models and added the foreignKey to the hasMany object.
    https://fiddle.sencha.com/#fiddle/2c4

    In what version of Touch are you experiencing this issue?
    Get more personalized support via a support subscription.

    Want to learn Sencha Touch 2? Check out
    Sencha training
    Sencha Touch in Action

    Need more help with your app? Hire Sencha Services services@sencha.com

    When posting code, please use BBCode's CODE tags.

    Need to include a test case use:
    The official Sencha Fiddle

  4. #4
    Sencha User
    Join Date
    Nov 2013
    Posts
    51
    Vote Rating
    1
    MonkeySleeve is on a distinguished road

      0  

    Default


    Quote Originally Posted by fmoseley View Post
    It should be. I was able to get it to work in the following modified version of your code using Touch 2.3.1
    I changed the idProperty on your models and added the foreignKey to the hasMany object.
    https://fiddle.sencha.com/#fiddle/2c4

    In what version of Touch are you experiencing this issue?
    I think that was it. The idProperty that is. Of course is something that small

    Thank you very much. This helped me a lot in understanding how associations work now.

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar