-
8 Mar 2012 6:28 AM #1
Final Release - problem binding nested data to models
Final Release - problem binding nested data to models
Hi,
Yesterday we updated our project to the Sencha 2 final release and code that was previously binding nested data successfully to associated models is no longer working correctly. It still binds the parent but only the first of the child records. Here is the code:
Store:
Parent Model:Code:Ext.define('PlayingPartner.store.CourseStore', { extend: 'Ext.data.Store', requires: ['Ext.data.Store', 'PlayingPartner.model.CourseSelection'], config: { storeId: 'courseStore', model: 'PlayingPartner.model.CourseSelection', proxy: { url: Ext.DataserviceBaseUrl + 'courseSelection', type: 'rest', reader: { type: 'json' } } } });
Child Model:Code:Ext.define('PlayingPartner.model.CourseSelection', { extend: 'Ext.data.Model', requires: ['PlayingPartner.model.CourseDiscipline'], config: { fields: [ { name: 'Id', type: 'int' }, { name: 'Name', type: 'string' }, { name: 'Shots', type: 'int' } ], hasMany: { model: 'PlayingPartner.model.CourseDiscipline', name: 'DisciplineList', associationKey: 'Disciplines' } } });
The data is being returned in the following format:Code:Ext.define('PlayingPartner.model.CourseDiscipline', { extend: 'Ext.data.Model', config: { fields: [ { name: 'Id', type: 'int' } ], belongsTo: 'PlayingPartner.model.CourseSelection' } });
As I said, this was working before the upgrade but perhaps there are syntax errors here that could be causing it to break with the new release.Code:[{ "Disciplines": [ {"Id":1} ], "Id":1, "Name":"One Shot", "Shots":1 }, { "Disciplines": [ {"Id":1}, {"Id":6}, {"Id":2}, {"Id":4}, {"Id":3}, {"Id":5} ], "Id":2, "Name":"Demonstration Course", "Shots":7 }]
Can anyone help?
Thanks.
-
8 Mar 2012 12:11 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
Using your code and this instance it all works for me with GA release:
Code:new PlayingPartner.store.CourseStore({ autoLoad : true, listeners : { load : function(store) { var rec = store.getAt(0), disciplines = rec.DisciplineList(); console.log(disciplines); } } });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.
-
8 Mar 2012 1:05 PM #3Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Redwood City, California
- Posts
- 3,659
- Vote Rating
- 14
Do you have any steps we might need to do to recreate the problem?
-
12 Mar 2012 12:37 AM #4
This is the code in my controller which is calling the load method on the store:
Still can't get it to work for us. Seems odd that it is binding the first child 'Discipline' of each item but no more.Code:Ext.define('PlayingPartner.controller.CourseSelection', { extend: 'PlayingPartner.controller.Base', requires: [ 'PlayingPartner.view.courseSelection.CourseList' ], init: function () { console.log('CourseSelection controller init method...'); window.me = this; }, config: { control: { backButton: { tap: function () { me.redirectToRoute('gamemode'); } }, drivingButton: { tap: function () { this.filterByDiscipline(1); } }, greensButton: { tap: function () { this.filterByDiscipline(2); } }, scramblingButton: { tap: function () { this.filterByDiscipline(3); } }, shortButton: { tap: function () { this.filterByDiscipline(4); } }, puttingButton: { tap: function () { this.filterByDiscipline(5); } }, fairwayButton: { tap: function () { this.filterByDiscipline(6); } } }, refs: { courseList: '#courseList', backButton: 'courselist navigationtitlebarwithaddplayers button[action=back]', drivingButton: 'button[action=driving]', greensButton: 'button[action=greens]', scramblingButton: 'button[action=scrambling]', shortButton: 'button[action=short]', puttingButton: 'button[action=putting]', fairwayButton: 'button[action=fairway]' }, routes: { 'courses/:id': 'load' } }, load: function (id) { console.log("round action of CourseSelection Controller"); me.setView('courselist', 'courseList'); var store = this.getCourseList().getStore(); store.load({ params: { gameMode: id} }); store.clearFilter(); },
Thanks.
-
14 Mar 2012 9:04 AM #5Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Redwood City, California
- Posts
- 3,659
- Vote Rating
- 14
Thank you for the test case.
-
28 Mar 2012 12:05 PM #6Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Haarlem, Netherlands
- Posts
- 1,235
- Vote Rating
- 5
Hi akpi,
Unfortunately I'm not able to reproduce this issue. When I run the following code using the json you provided the disciplines are correctly loaded.
Code:Ext.define('PlayingPartner.store.CourseStore', { extend: 'Ext.data.Store', config: { storeId: 'courseStore', model: 'PlayingPartner.model.CourseSelection', proxy: { url: 'disciplines.json', type: 'rest', reader: { type: 'json' } } } }); Ext.define('PlayingPartner.model.CourseSelection', { extend: 'Ext.data.Model', config: { fields: [ { name: 'Id', type: 'int' }, { name: 'Name', type: 'string' }, { name: 'Shots', type: 'int' } ], hasMany: { model: 'PlayingPartner.model.CourseDiscipline', name: 'DisciplineList', associationKey: 'Disciplines' } } }); Ext.define('PlayingPartner.model.CourseDiscipline', { extend: 'Ext.data.Model', config: { fields: [ { name: 'Id', type: 'int' } ], belongsTo: 'PlayingPartner.model.CourseSelection' } }); Ext.setup({ onReady: function() { var store = Ext.create('PlayingPartner.store.CourseStore'); store.load({ params: { gameMode: 5}, callback: function() { console.log(store); }}); } });
Is there anything else that you think might cause the associations to load? Anything in your setup that is slightly different then the test case I've created?
Best,
Tommy
Looks like we cannot reproduce this. Please provide another test case to reproduce this issue.


Reply With Quote
