Results 1 to 3 of 3

Thread: hasMany association data object empty

  1. #1
    Sencha Premium Member
    Join Date
    Nov 2011
    Location
    Netherlands
    Posts
    87
    Vote Rating
    1
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha Premium Member
    Join Date
    Nov 2011
    Location
    Netherlands
    Posts
    87
    Vote Rating
    1
      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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •