PDA

View Full Version : Associated Model does not generate id automatically



a.premkumar
10 Oct 2012, 10:58 PM
Hi All,

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

model ColumnState.js


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


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.



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.

mitchellsimoens
15 Oct 2012, 8:05 AM
I believe this is due to the reader needing to get involved