-
3 Apr 2012 7:26 PM #1
Answered: Accessing hasMany object localy not working?
Answered: Accessing hasMany object localy not working?
What am I doing wrong?
In Sencha Touch 1, it was possible to call a Store like that this.tvProviders(); where tvProviders is the name in the hasMany properties. In Sencha Touch 1, that did return a tvProvidersStore object.
In Sencha Touch 2 I get this error : TypeError: 'undefined' is not a function (evaluating 'this.tvProviders()')Code:Ext.define("MyApp.model.configs.TvProviderList", {extend: "Ext.data.Model", configs: { hasMany: {model: 'MyApp.model.configs.TvProvider', name: 'tvProviders'} }, constructor: function() { this.callParent(arguments); var tvpStore = this.tvProviders(); } } );
Any idea how to solve that. I really need to access it locally. Can't load external data by Proxy. I want to be able to add TvProvider Class object in that like :
var tvpStore = this.tvProviders();
tvpStore.add(aTvProviderInstance);
-
Best Answer Posted by mitchellsimoens
This is working for me:
Code:Ext.define('Search', { extend : 'Ext.data.Model', config : { fields : [ 'id', 'query' ], hasMany : { model : 'Tweet', name : 'tweets' } }, constructor : function() { this.callParent(arguments); var store = this.tweets(); console.log(store); } }); Ext.define('Tweet', { extend : 'Ext.data.Model', config : { fields : [ 'id', 'text', 'from_user' ] } }); Ext.application({ name : 'Test', launch : function () { new Search({query: 'Sencha Touch'}); } });
-
4 Apr 2012 5:26 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 434
- Answers
- 3102
This is working for me:
Code:Ext.define('Search', { extend : 'Ext.data.Model', config : { fields : [ 'id', 'query' ], hasMany : { model : 'Tweet', name : 'tweets' } }, constructor : function() { this.callParent(arguments); var store = this.tweets(); console.log(store); } }); Ext.define('Tweet', { extend : 'Ext.data.Model', config : { fields : [ 'id', 'text', 'from_user' ] } }); Ext.application({ name : 'Test', launch : function () { new Search({query: 'Sencha Touch'}); } });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.
-
4 Apr 2012 6:47 AM #3
I'm having a similar issue about this one. Let's say for example I want to add a collection of tweets, when instantiating the Search model. The problem I'm facing is that this collection is not stored in the data holder, but rather in the raw property.
Code:var test = new Search({query: 'Sencha Touch', tweets: [{id: 'testId1', text: 'testText1', from_user: 'sampleUser1'}, {id: 'testId2', text: 'testText2', from_user: 'sampleUser2'}]}); [COLOR=rgba(255, 255, 255, 0.699219)][/COLOR] Object undefined test [COLOR=rgba(255, 255, 255, 0.699219)][/COLOR] Object- _data: Object
- data: Object
- id: "ext-record-326"
- query: "Sencha Touch"
- __proto__: Object
- id: "ext-record-326"
- internalId: "ext-record-326"
- modified: Object
- phantom: true
- raw: Object
- query: "Sencha Touch"
- tweets: Array (2)
- __proto__: Object
- stores: Array (0)
- tweetsStore: Object
- __proto__: Object
- I want these tweets to be stored in the data property, because after that I'm calling the model.save() method, which uses exactly that data.
- I tried the same logic, but done with stores and in that case the association is working fine.
-
4 Apr 2012 6:52 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 434
- Answers
- 3102
That is because the associated data (event if returned from a server call) is not attached to the data at all. It's on the store/model instance that is created from the association.
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.
-
4 Apr 2012 7:15 AM #5
Hmm. That's a little bit strange, because when I'm using a json object coming from a server(invoked before that with store.load() func) the results are different. I mean in the data field of the "A" class, I see the collection of "B" classes. And the association is A has many B. Why is that happening ? If I use a store, defined with models and associations the data is ok. But if I take the json result from server and hardcode it in the model's constructor or pass it as a parameter in Ext.create() function, the result is different ...
-
4 Apr 2012 12:18 PM #6
Ok
Human mistake
configs: {}
instead of
config: {}
Don't tell anyone


Reply With Quote