We had this same problem in sencha touch.. the solution was like this..
This code is in a button click handler for a 'create new assessment' button. The idea is that a create call is supposed to be made to the server and the result of that call should be an 'Assessment.' The json stream coming back has entries for all of the related items (e.g. categories, assessor, etc).
Code:
var me = this;
// create a new assessment with the client and tool
var newOne = Ext.create('helium.model.Assessment');
// save it so that the 'create' call will happen on the server
newOne.save({
success: function (record) {
// for some reason the 'create' flow doesn't resolve associations
// need to manually push through a reader
var reader = Ext.create('Ext.data.reader.Json', {
model: 'helium.model.Assessment'
});
var resultSet = reader.read(record.data); //the record itself won't work, just the .data portion
var assessment = resultSet.getRecords()[0];
// 'assessment' is now fully read in with associations
},
scope: me
});
Here's the model object (using a REST proxy).. the writer is a custom writer that will also push all of the related items down on a save/update call..
Code:
Ext.define('helium.model.Assessment', {
extend: 'Ext.data.Model',
config: {
useCache: false,
fields: [
'id', 'version', 'startDate', 'type',
{name: 'allowedActions', persist: false},
{name: 'status', persist: false},
{name: 'baseType', persist: false},
{name: 'major', persist: false},
{name: 'minor', persist: false}
],
hasMany: [
{model: 'helium.model.Category', name: 'categories'}
],
hasOne: [
{model: 'helium.model.Assessor'},
{model: 'helium.model.OrgUnit'},
{model: 'helium.model.Client'}
],
proxy: {
type: 'rest',
writer: Ext.create('helium.util.IncludeRelationshipJsonWriter'),
api: {
create: '../data/assessment/create',
read: '../data/assessment/read',
update: '../data/assessment/update',
destroy: '../data/assessment/delete'
},
reader: {
type: 'json',
rootProperty: 'assessment'
}
}
}
});