-
22 Mar 2012 7:24 AM #1
Has Many with localstorage
Has Many with localstorage
Hello,
Can I have hasMany associations with localstorage?
For example I have two models, Recurso and Concejo.
Concejo has belongsTo associations, and it works correctly, but Recurso has hasMany associations and when I execute miConcejo.recursos(), I receive an empty "Ext.data.Store".
Recurso.js (Ext.data.Model)
Concejo.js (Ext.data.Model)Code:Ext.define('app.model.Recurso', { extend: 'Ext.data.Model', config: { fields: [ {name: "id", type: "int"}, {name: "nombre", type: "string"}, {name: "concejo_id", type: "int"}, ], associations: [ { type: 'belongsTo', model: 'app.model.Concejo' } ], proxy: { type: 'localstorage', id : 'app-recursos' } } });
Concejos.js (Ext.data.Store)Code:Ext.define('app.model.Concejo', { extend: 'Ext.data.Model', requires : [ 'app.model.Recurso' ], config: { fields: [ {name: "id", type: "int"}, {name: "nombre", type: "string"} ], associations: [ { type: 'hasMany', model: 'app.model.Recurso', associationKey: 'recursos', } ], proxy: { type: 'localstorage', id : 'app-concejos' } } });
Recursos.js (Ext.data.Store)Code:Ext.define('app.store.Concejos', { extend: 'Ext.data.Store', requires: [ 'app.model.Concejo' ], config: { model: 'app.model.Concejo', storeId: 'ConcejosStore', autoLoad: true, data: [ { id: "1", nombre: 'Concejo 1' }, { id: "2", nombre: 'Concejo 2'}, { id: "3", nombre: 'Concejo 3' } ] } });
Thank you very much.Code:Ext.define('app.store.Recursos', { extend: 'Ext.data.Store', requires: [ 'app.model.Recurso' ], config: { model: 'app.model.Recurso', storeId: 'RecursosStore', autoLoad: true, sorters: [ { property: 'nombre', direction: 'ASC' } ], data: [ { "id": "1", "nombre":"Recurso 1", "concejo_id": "2", }, { "id": "2", "nombre":"Recurso 2", "concejo_id": "1", } ] } });
-
22 Mar 2012 12:21 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
You should be able to but saving associated data is not supported.
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.
-
15 Jun 2012 8:02 AM #3
Yours is the latest in a long list of related requests. Some brief background:
1/20/2012 - ST team "promised" the feature in ST2 GA Release - Not delivered
http://www.sencha.com/forum/showthre...ociated-models
5/1/2012 - ST team promised the feature in ST2.1 - No updates for a month and a half
http://www.sencha.com/forum/showthre...ssociated-data
Now, we're reminded that it is not supported... with no commitment to fix the issue. So... Sencha Touch is still a great choice to build a gorgeous UI, but the data package is incomplete (my opinion), and there is no reason to think that will change any time soon. On the other hand, it's free so I can't really complain :o\
-
18 Jun 2012 11:50 AM #4
I am in the process of porting an app from ST1 to ST2. I had hasmany associations saving to local storage with no problems in version 1.
This app is useless if I cant save the related items to local storage. When will this be coming? Is there a work around?
-
18 Jun 2012 12:14 PM #5
-
18 Jun 2012 12:18 PM #6
This is the first I've heard that Ed is leaving. Hopefully someone else on the team can finish the good work that Ed started.
Edit: Best wishes to Ed wherever he may be headed.Last edited by Bunchofstring; 18 Jun 2012 at 12:38 PM. Reason: Farewell
-
19 Jun 2012 1:39 AM #7
What's the solution?
What's the solution?
Ok, so now it's clear that sencha doesn't support localstorage with has many associations. So, is there any solution or trick to manage this manually?
-
19 Jun 2012 1:56 AM #8
You could work without hasmany and use a filter where neccessary.
But filter has some bugs to, for example:
http://www.sencha.com/forum/showthre...ks-incorrectly
http://www.sencha.com/forum/showthread.php?211626-Dataview-and-Store-Filtering
http://www.sencha.com/forum/showthre...pected-results
-
19 Jun 2012 3:04 AM #9
I think that this is not correct. We can save associated data by using separate store for association.
http://www.sencha.com/forum/showthre...l=1#post835806
-
1 Jul 2012 8:28 AM #10
I just added a basic test harness with a few test cases at https://github.com/bunchofstring/ST2_Associations. This is my first time setting up a git repository, so I may need help with permissions if folks are willing to help work on this.
- ST2 library (-all-debug) and css
- index.html
- app.js
- Model idProperty wasn't always working as documented, so I created a new unique identifier strategy to address that issue.
- UI to clear localStorage and reload or just reload. The body also shows the results of three test cases I came up with.


Reply With Quote