PDA

View Full Version : What is the meaning of type in association



hudi1
19 Jun 2013, 3:34 AM
Hi,

I have model with association:


Ext.define("SimpleWeb.model.Relative", { extend : "Ext.data.Model", fields : [ { name : "id", type : "int" }, { name : "personId", type : "int" }, { name : "version", type : "int" } ], associations : [ { type : "belongsTo", model : "SimpleWeb.model.Person", associationKey : "relPerson", foreignKey : "person_id", setterName : "setRelPerson", getterName : "getRelPerson" } ] });

this works good. Just for test I change type to hasOne and this works also good. So what is the meaning of this type? I thing important is other parameters like getter ...

Songle
19 Jun 2013, 11:15 PM
type is so you can tell the model what type of data is coming, 'int' or 'string' or 'boolean' or 'date'

hudi1
19 Jun 2013, 11:44 PM
but now I am talking about association. Different between belongsTo and hasOne

Songle
19 Jun 2013, 11:49 PM
ah, sorry about that. Perhaps a real life example then



Ext.define('Songle.model.SetListSongs', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields: [
{ name:'occ', type:'int' },
{ name:'song_id', type:'string' },
{ name:'title', type:'string' },
{ name:'key', type:'string' },
{ name:'length', type:'string' }
],
belongsTo: 'Songle.model.SetListWin'
});

Ext.define('Songle.model.SetListWin', {
extend: 'Ext.data.Model',
idProperty: 'setlistId',
fields: [
{ name: 'title', type:'string' },
{ name: 'setlistId', type:'int' },
{ name: 'date', type:'string' },
{ name: 'parenttxt', type:'string' },
{ name: 'totaltime', type:'string' }
],
hasMany: [ {model: 'Songle.model.SetListSongs', name: 'songs'} ]
});

var myStore = Ext.create('Ext.data.Store', {
id:'SetlistWinStore',
model: 'Songle.model.SetListWin',
autoLoad: false
});


In this example you can see how all my songs "belongTo" a setlist and my setlist "hasMany" songs.

hudi1
20 Jun 2013, 12:51 AM
and did you try change it ? belongsTo change to hasMany and vice versa ?