jeudi 18 septembre 2014

How to set dynamically an associated model?

I have a model class "User" that has an association with "Job":

Code:



Ext.define('Fiddle.model.User', {
extend: 'Fiddle.model.Base',


fields: [{
name: 'name',
type: 'string'
}, {
name: 'jobId',
type: 'int',
reference: 'Job'
}]
});

When I do below code it works properly:


Code:



var user = Fiddle.model.User.load(1);
alert(user.job.get('name')); //It works

But I am not able to create a model with association. I tried:


Code:



var newUser = Ext.create('Fiddle.model.User');
newUser.set({name: 'Bill', job: {id: 2, name: 'developer'}});
alert(newUser.job.get('name')); //It breaks because there is no job associated

How could I do this?

Here you can see the fiddle: http://ift.tt/1r4JM5Q


Thanks






How to set dynamically an associated model?

Aucun commentaire:

Enregistrer un commentaire