-
30 May 2012 4:38 AM #1
Answered: hasmany relation two models one store trouble bubble
Answered: hasmany relation two models one store trouble bubble
Model Item
Model LinkeditemsCode:Ext.define('stockwiz.model.Item', { extend: 'Ext.data.Model', config: { fields: [ { name: '_id', type: 'string' }, { name: 'name', type: 'string' }, ], hasMany: {model: 'Linkeditems', name: 'linkeditems'}, } });
JSON into Item StoreCode:Ext.define('stockwiz.model.Linkeditems', { extend: 'Ext.data.Model', config: { fields: [ { name: '_id', type: 'string' }, { name: '_item_id', type: 'string' }, { name: 'quantity', type: 'float' }, { name: 'notes', type: 'string' }, ], belongsTo: 'Item' } });
Funny error when doing:Code:{ "_id": "4fc608e66a41a65814000001", "name": "product link test", "linkeditems": [ { "_item_id": "4fc5c91804e17e0100000001", "quantity": 10, "notes": "" }, { "_item_id": "4fc5afeed501360100000002", "quantity": 1, "notes": "" } ] }
TypeError: 'undefined' is not an object (evaluating 'storeItem.linkeditems.getCount')Code:var myStore = Ext.StoreMgr.get('Item'); var storeItem = myStore.first(); console.log('linkeditems count: '+storeItem.linkeditems.getCount());
Whats wrong with that has-many setup?
Kinda tried to take over logic from http://docs.sencha.com/touch/2-0/#!/....reader.Reader
Thanks for any hints...
-
Best Answer Posted by mitchellsimoens
Try setting the associationKey config in the hasMany config to "linkeditems"
-
31 May 2012 5:56 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
Try setting the associationKey config in the hasMany config to "linkeditems"
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.
-
31 May 2012 6:15 PM #3
thanks for the response, but this didn't help either.
will just go back to the old-fashioned-kinda way of having a separate store and do the linking with filters instead
cheers...


Reply With Quote