-
23 Apr 2012 1:17 PM #11
Hey,
Thanks for the help so far but unfortunately no luck - here is the code I have been trying for reference - is there something I'm completely missing here?
Group.js model
Team.js modelCode:Ext.define('Application.model.Group', { extend: 'Ext.data.Model', config: { fields: [ {name: 'name', type: 'string'} ]}, hasMany: {model: 'Team', name: 'teams'} /* associations: [ {type: 'hasMany', model: 'Team', name: 'teams'} ] */ });
Code:Ext.define('Application.model.Team', { extend: 'Ext.data.Model', config: { fields: [ {name: 'id', type: 'string'}, {name: 'team_info', type: 'string'}, {name: 'against', type: 'int', mapping: 'competition_data.Against'} ]}, belongsTo: 'Group' //belongsTo: {model: 'Group', name: 'group'} /* associations: [ {type: 'belongsTo', model: 'Group', name: 'group'} ] */ });
-
23 Apr 2012 1:20 PM #12Sencha - Community Support Team
- Join Date
- Jan 2009
- Location
- Palo Alto, California
- Posts
- 1,941
- Vote Rating
- 6
- Answers
- 29
I think the problem is your associations are still being defined outside the config object. They need to move inside. Your indentation actually hides the issue - if I reformat your code to use a consistent indentation approach it looks like this:
Note that the hasMany is outside the config object. It needs to move inside the config object so it ends up looking like this:Code:Ext.define('Application.model.Group', { extend: 'Ext.data.Model', config: { fields: [ {name: 'name', type: 'string'} ] }, hasMany: { model: 'Team', name: 'teams' } });
The same applies to the Team modelCode:Ext.define('Application.model.Group', { extend: 'Ext.data.Model', config: { fields: [ {name: 'name', type: 'string'} ], hasMany: { model: 'Team', name: 'teams' } } });Ext JS Senior Software Architect
Personal Blog: http://edspencer.net
Twitter: http://twitter.com/edspencer
Github: http://github.com/edspencer
-
23 Apr 2012 1:29 PM #13
Hi,
Thanks for helping me out but tried that and still no luck unfortunately. Been trawling the internet too for an answer and so many places give so many different ways to do things. Here is my code now:
Group.js
Team.jsCode:Ext.define('Application.model.Group', { extend: 'Ext.data.Model', config: { fields: [ {name: 'name', type: 'string'} ], hasMany: {model: 'Team', name: 'teams'} } });
Code:Ext.define('Application.model.Team', { extend: 'Ext.data.Model', config: { fields: [ {name: 'id', type: 'string'}, {name: 'team_info', type: 'string'}, {name: 'against', type: 'int', mapping: 'competition_data.Against'} ], belongsTo: {model: 'Group', name: 'group'} } });
Do I have to do anything in the Store for Groups to loop through each Group model and associate each team with it or should each team encountered be automatically instantiated and assigned to the correct group?
I've read about association keys, are they something that has been deprecated or for some other reason is no longer needed?
-
23 Apr 2012 1:32 PM #14Sencha - Community Support Team
- Join Date
- Jan 2009
- Location
- Palo Alto, California
- Posts
- 1,941
- Vote Rating
- 6
- Answers
- 29
Oh - you're not fully qualifying the model name. Try this:
Code:Ext.define('Application.model.Group', { extend: 'Ext.data.Model', config: { fields: [ {name: 'name', type: 'string'} ], hasMany: { model: 'Application.model.Team', name: 'teams' } } });Ext JS Senior Software Architect
Personal Blog: http://edspencer.net
Twitter: http://twitter.com/edspencer
Github: http://github.com/edspencer
-
23 Apr 2012 1:41 PM #15
It worked (almost) so thank you so much for that - only thing is it's only returning the first team for each group pulled from the json feed as opposed to all four teams. Must figure out how I can get it to access all teams.
Thanks a million!
Matt
-
23 Apr 2012 1:44 PM #16
Only one team was coming up for each group and I've found the culprit:
In Team.js I had the line
which would then load the group for the team, which in turn would load the team for that group and it must have been caught in an infinite loop - possibly a bug ?Code:belongsTo: {model: 'Application.model.Group', name: 'groups'}
I took it out and now the group with all teams associated with them are loading correctly.
Once again thanks a million for your help
-
23 Apr 2012 1:51 PM #17Sencha - Community Support Team
- Join Date
- Jan 2009
- Location
- Palo Alto, California
- Posts
- 1,941
- Vote Rating
- 6
- Answers
- 29
That's weird... the name: 'groups' is actually not required in that association anyway, maybe it's interfering. If not that could well be a bug.
Anyway glad you got it working
Ext JS Senior Software Architect
Personal Blog: http://edspencer.net
Twitter: http://twitter.com/edspencer
Github: http://github.com/edspencer
-
7 Nov 2012 6:15 AM #18
I have the same issue, with my associations , my 'docs' are empty
- data: Object
- CON_BIRTHDAY: Mon Jan 19 1942 01:00:00 GMT+0100 (Paris, Madrid)
- CON_FIRSTNAME: "Alain"
- CON_ID: "1"
- CON_LASTNAME: "ESSAI"
- CON_MAIL: "sebastien@fsd-france.com"
- CON_MSG: "Envoyer un courrier↵Prendre rendez-vous"
- GRP_ID: 3
- UPL_ID: "1"
- docs: Array[0]
- raw: Object
- ADR_ID: "62"
- COF_ID: "1"
- CON_BIRTHDAY: "1942-01-19"
- CON_DELETE: "0"
- CON_FIRSTNAME: "Alain"
- CON_ID: "1"
- CON_LASTNAME: "ESSAI"
- CON_MAIL: "sebastien@fsd-france.com"
- CON_MSG: "Envoyer un courrier↵Prendre rendez-vous"
- CON_SOURCE: "professionnel"
- CPD_ID: "4"
- GEN_ID: "1"
- GRP_ID: "3"
- UPL_ID: "1"
- docs: Array[8]
- What was the trick for making this work ?
- data: Object


Reply With Quote