1. #1
    Sencha User
    Join Date
    Jan 2013
    Posts
    19
    Vote Rating
    0
    ikean is on a distinguished road

      0  

    Default 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":

    Code:
    // method 1, access model type through the manager
    var UserType = Ext.ModelManager.getModel('User');
    // method 2, reference the type directly
    var UserType=User;
    This does not seem to be the case, however. Take this simple example:

    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');
    (Working example here: http://new.senchafiddle.com/#/KcBy6/)


    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.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    898
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    This code isn't really valid for what you usually want to have:

    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',
        }
      }
    });
    The singleton property will automatically create an instance so Config will be an instance not a definition.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Jan 2013
    Posts
    19
    Vote Rating
    0
    ikean is on a distinguished road

      0  

    Default


    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?

Thread Participants: 1

Tags for this Thread