1. #1
    Sencha Premium Member
    Join Date
    Nov 2011
    Location
    Netherlands
    Posts
    87
    Vote Rating
    0
    macs is on a distinguished road

      0  

    Default hasMany association data object empty

    hasMany association data object empty


    i am loading two sets of data form my server using two stores (a shop store and a product store) configured with jsonp proxies and json readers. the models the stores are configured with are associated by the logic a shop has many products. the two datasets i retrieve contain identifiers that indicate the association between each product with its shop. the problem is however that the (filtered) product store data object is empty. when i don't use the association config in the models but filter the product store manually everything works as it should. What am i doing wrong here?

    in an itemtap event handler i do console.log(record.products()); or simply console.log(record), in both cases the associated data object is empty. everything seems to be set correctly though.

    the shops model

    Code:
    Ext.define('VB1.model.shop.ShopModel', {
        extend: 'Ext.data.Model',
        requires:['VB1.model.prod.ProdModel'],
        config: {
            fields: [
                {name: 'id', mapping: 'm_url'}, //the unique shop id
                 {name: 'title', type: 'string'},
            ],
              hasMany: {model: 'VB1.model.prod.ProdModel', name: 'products',  foreignKey: 'shop_id', autoLoad: true},// i actually need this last  config?},
        },
    });
    the products model

    Code:
    Ext.define('VB1.model.prod.ProdModel', {
        extend: 'Ext.data.Model',
        config: {
            fields: [
                {name: 'id', mapping: 'm_url'}, //the unique products id
                {name: 'shop_id', mapping: 'shop.url'}, //reference to the unique shop id
                 {name: 'title', type: 'string'},
            ],
            belongsTo: {model: 'VB1.model.shop.ShopModel'},
        },
    });

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,650
    Vote Rating
    899
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    record.products() will return a store. If the data was loaded with the store was loaded then it will have data right away. If it has to load data then the store will be loading. Are you waiting till after the store loads? Have you looked at the response?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

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

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

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

  3. #3
    Sencha Premium Member
    Join Date
    Nov 2011
    Location
    Netherlands
    Posts
    87
    Vote Rating
    0
    macs is on a distinguished road

      0  

    Default


    thanks for your reply Mitchell. for now i decided to filter the stores manually. as far as i understand the docs correctly (which i am not totally sure of), configuring model relationships causes sencha to create a filtered store automatically for me upon request. actually i do not need a new store, filtering the existing will do just fine and should cost less resources. if i all got it wrong and that is exactly what sencha does than it should performance wise make no difference whether i do it manually or let the framework do the work. so i decided to go with the first option

Thread Participants: 1

Tags for this Thread