PDA

View Full Version : How does the hasMany and belongsTo works ?



Elfayer
25 Sep 2012, 6:36 AM
Hi I have two models :

Ext.define('EXC.model.Folder', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int' },
{ name: 'name', type: 'string' }
],
proxy: {
type: 'ajax',
actionMethods: {
read: 'POST'
},
api: {
read: '/File/GetFolder/'
}
},
associations: [{
type: 'hasMany',
model: 'File',
primaryKey: 'fil_parent_id',
foreignKey: 'id',
autoload: true
}]
});




Ext.define('EXC.model.File', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', mapping: 'fil_id', type: 'int' },
{ name: 'name', mapping: 'fil_label', type: 'string' },
{ name: 'fil_parent_id', type: 'int' },
{ name: 'fil_is_folder', type: 'bool' },
{ name: 'fil_description', type: 'string' },
{ name: 'fil_name', type: 'string' },
{ name: 'pth_id', type: 'int' },
{ name: 'ftp_id', type: 'int' },
{ name: 'fil_created', type: 'date', dateFormat: 'Y-m-dTH:i:s' },
{ name: 'fil_updated', type: 'date', dateFormat: 'Y-m-dTH:i:s' },
{ name: 'fil_expired', type: 'date', dateFormat: 'Y-m-dTH:i:s' },
{ name: 'fil_removed', type: 'bool' },
{ name: 'fil_deleted', type: 'bool' },
{ name: 'usr_id', type: 'int' },
{ name: 'fil_editor', type: 'bool' }
],
proxy: {
type: 'ajax',
actionMethods: {
read: 'POST'
},
api: {
read: '/File/GetFiles/'
}
},
associations: [{
type: 'belongsTo',
model: 'Folder',
primaryKey: 'id',
foreignKey: 'id'
}]
});

I would like to know : How, if it's possible, can I fill automatically the File store when I fill the Folder store?

Elfayer
25 Sep 2012, 11:14 PM
I still have a problem to fill the File store.

redraid
26 Sep 2012, 1:13 AM
folderRecord.files().load({
callback: function () {
alert('Files loaded');
}
});