Results 1 to 2 of 2

Thread: Associated Model does not generate id automatically

  1. #1
    Sencha User
    Join Date
    Mar 2012
    Location
    Chennai, India
    Posts
    90
    Answers
    8
    Vote Rating
    5
      0  

    Default Unanswered: Associated Model does not generate id automatically

    Hi All,

    I have two models. They are related to each in hasMany-belongsTo manner.

    model ColumnState.js
    Code:
    Ext.define('ExtMVC.model.ColumnState',
    {
        extend:'Ext.data.Model',
        //requires:['ExtMVC.model.PortalState'],
        fields:
        [
            {name:'columnstate_id',type:'int'},
            {name:'columnIndex',type:'int'}
        ],
        
        associations: 
        [
            {
                type: 'hasMany',
                model: 'ExtMVC.model.PortalState',
                associatedName: 'PortalState',
                getterName: 'getPortalState',
                setterName:'setPortalState',
                name: 'portalstate',
                foreignKey: 'portalstate_id',
                instanceName: 'portalstate'
              }
          ],
          
          proxy: 
        {
            type: 'localstorage',
            id  : 'columnstate'
        }
        
    });
    model PortalState.js
    Code:
    Ext.define('ExtMVC.model.PortalState',
    {
        extend:'Ext.data.Model',
        //requires:['ExtMVC.model.ColumnState'],
        fields:
        [
            {name:'portalstate_id',type:'int'},
            {name:'columnstate_id',type:'int'},
            {name:'portalIndex',type:'int'},
            {name:'portalWidth',type:'int'},
            {name:'portalHeight',type:'int'},
            {name:'collapsible',type:'string'}
        ],
        
        associations: 
        [
            {
                type: 'belongsTo',
                model: 'ExtMVC.model.ColumnState',
                associatedName: 'ColumnState',
                getterName: 'getColumnState',
                setterName:'setColumnState',
                name: 'columnstate',
                foreignKey: 'columnstate_id',
                instanceName: 'columnstate'
              }
          ],
          
          proxy: 
        {
            type: 'localstorage',
            id  : 'portalstate'
        }
    });
    I am trying to save data manually first. I am using the following code.

    Code:
    var column1 = Ext.create('ExtMVC.model.ColumnState',{columnstate_id:1,columnIndex:0});
    var column2 = Ext.create('ExtMVC.model.ColumnState',{columnstate_id:2,columnIndex:1});
    var column3 = Ext.create('ExtMVC.model.ColumnState',{columnstate_id:3,columnIndex:2});
    
    
    // Column wolud not generate portalstate() method if I do not instantiate atleast a portalstate model.
    var port1 = Ext.create('ExtMVC.model.PortalState'); //<=============
                   
    var portal1 = column1.portalstate();
    var portal2 = column2.portalstate();
    var portal3 = column3.portalstate();
    
    
    column1.save();
    column2.save();
    column3.save();
                   
    portal1.add([{portalIndex:0,portalWidth:367,portalHeight:300,collapsible:'false'},{portalIndex:1,portalWidth:367,portalHeight:330,collapsible:'false'}]);
    portal1.sync();
    portal2.add([{portalIndex:0,portalWidth:367,portalHeight:150,collapsible:'false'},{portalIndex:1,portalWidth:367,portalHeight:330,collapsible:'false'}])
    portal2.sync();
    portal3.add({portalIndex:0,portalWidth:367,portalHeight:300,collapsible:'false'});
    portal3.sync();
    Please help me. And also in the instantiation issue too.

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,318
    Answers
    3883
    Vote Rating
    1292
      0  

    Default

    I believe this is due to the reader needing to get involved
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •