-
17 Feb 2013 1:41 PM #1
This behavior seems contrary to the documentation, can someone please explain?
This behavior seems contrary to the documentation, can someone please explain?
The ModelManager documentation states "The following snippets are equivalent":
This does not seem to be the case, however. Take this simple example:Code:// method 1, access model type through the manager var UserType = Ext.ModelManager.getModel('User'); // method 2, reference the type directly var UserType=User;
(Working example here: http://new.senchafiddle.com/#/KcBy6/)Code:Ext.define('Config', { singleton: true, extend: 'Ext.data.Model', config: { fields: [ {name: 'id', type: 'int'}, {name: 'email', type: 'string'}, {name: 'password', type: 'string'}, {name: 'username', type: 'string'}, ], proxy: { type: 'localstorage', id: 'config', } } }); var ConfigModel = Ext.ModelManager.getModel('Config');
Given the code above, here's the odd part:
Directly
Config.save() exists.
Config.load() doesn't exist.
via ModelManager
ConfigModel.save() doesn't exist.
ConfigModel.load() does exist.
What is going on here? Why don't I have consistent access to load() and save()? This not only seems very odd, but also appears to contradict the whole equivalency thing mentioned in the ModelManager documentation.
-
19 Feb 2013 10:32 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,085
- Vote Rating
- 453
This code isn't really valid for what you usually want to have:
The singleton property will automatically create an instance so Config will be an instance not a definition.Code:Ext.define('Config', { singleton: true, extend: 'Ext.data.Model', config: { fields: [ {name: 'id', type: 'int'}, {name: 'email', type: 'string'}, {name: 'password', type: 'string'}, {name: 'username', type: 'string'}, ], proxy: { type: 'localstorage', id: 'config', } } });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 2013 11:07 AM #3
Are there any downsides to our Model being an instance v.s. a definition?
Am I losing anything by not having a definition available?
Can I recall the definition through an instance (e.g. Config.constructor)?
What is the difference between a definition of an instance in Ext.js/Touch?
As I saw/see it, my application will only ever have one single user. In this case, there is no need to use a Store (which looks from just about every documented example to be intended as a collection of instances).
Am I correct in this understanding?


Reply With Quote