-
20 May 2012 5:41 AM #1
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
the products modelCode: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?}, }, });
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'}, }, });
-
22 May 2012 5:01 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,710
- Vote Rating
- 436
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
________________
http://www.JSONPLint.com - Source to lint your JSONP!
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 almost in print!
When posting code, please use BBCode's CODE tags.
-
23 May 2012 11:45 PM #3
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


Reply With Quote