PDA

View Full Version : Did belongsto works with dots ?



vladka
4 Nov 2011, 11:30 AM
Hello everybody.

BelongsTo don't works with model like: Appname.model.ModelName.


Ext.define('Panda.model.Product', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int' },
{ name: 'manifactor_id', type: 'int' },
{ name: 'name', type: 'string' }
],
associations: [ {
type: 'belongsTo', model: 'Panda.model.Manifactor', 'name' : 'manifactor',
}]
});


two classes to make tests - http://pastebin.com/jE5rkfmW

Is it possible to make it's works ?

Or don't use associations at all ?

whalethewise
4 Nov 2011, 11:37 AM
I use it like this and it works for me:



Ext.define('com.MyApp.model.Document', { extend: 'Ext.data.Model',
fields: documentModelMainFields,
hasMany: {
model: 'com.MyApps.model.Attribute',
name: 'attributes'
}
});


Ext.define('com.MyApp.model.Attribute',{
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'float'},
{name:'name'},
{name: 'value'},
{name: 'document_id', type: 'float'}
],
belongsTo: {
model: 'com.MyApp.model.Document',
foreignKey: 'document_id'
}


});

vladka
4 Nov 2011, 12:07 PM
if i change


associations: [ { type: 'belongsTo', model: 'Panda.model.Category' }, ]
to


belongsTo: { model: 'Pandora.model.Category', foreignKey: 'id', name: 'category', }

p = new Pandora.model.Product()
p.associations.keys - get the right value.

But how to get a category ?

p.getCategory - return error function underfined

vladka
4 Nov 2011, 5:24 PM
found getterName parameter in source code belongto.js

getterName : 'getCategory'.

thats i needed.