-
18 Feb 2012 10:48 PM #1
Can't define a custom association (ST2-B3)
Can't define a custom association (ST2-B3)
In our project we would like to create a custom association class that works a little bit different than the belongsTo association. Unfortunately this seemingly old piece of code in Ext.data.association is giving me a headache:
Could you change default: to Ext.create(association.type)?Code:statics: { create: function(association) { if (!association.isAssociation) { if (Ext.isString(association)) { association = { type: association }; } switch (association.type) { case 'belongsTo': return Ext.create('Ext.data.association.BelongsTo', association); case 'hasMany': return Ext.create('Ext.data.association.HasMany', association); case 'hasOne': return Ext.create('Ext.data.association.HasOne', association); default: //<debug> Ext.Logger.error('Unknown Association type: "' + association.type + '"'); //</debug> } } return association; } }
I think that the switch is somewhat nasty
-
19 Feb 2012 7:45 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
I think instead of the switch it could try to resolve the association class name based ont he type being passed in and the alias of the associations themselves.
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.
-
19 Feb 2012 12:16 PM #3Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Haarlem, Netherlands
- Posts
- 1,235
- Vote Rating
- 4
Alright, this has been fixed for the next release.
The only thing that I think you might run into is the fact that reading in associated data in Model.js is checking for the type on the association. If you make a custom one, this code would not be triggered.
-
20 Feb 2012 4:50 PM #4
-
30 Aug 2012 12:02 PM #5
Any chance this could get applied to the main ExtJS 4.1 code as well?
-
8 Apr 2013 6:57 AM #6
I fixed the problem with this patch. Waiting for the new release though.
Code:statics: { create: function(association){ if (Ext.isString(association)) { association = { type: association }; } switch (association.type) { case 'belongsTo': return new Ext.data.association.BelongsTo(association); case 'hasMany': return new Ext.data.association.HasMany(association); case 'hasOne': return new Ext.data.association.HasOne(association); default: // I hope this works with the fix in the new version return Ext.createByAlias('association.' + association.type.toLowerCase(), association); } return association; } },
Success! Looks like we've fixed this one. According to our records the fix was applied for
TOUCH-2122
in
2.0.


Reply With Quote
