View Full Version : Mapping form to a nested model

30 Jul 2014, 6:02 AM

I have a simple model with some "hasOne" associations. Here the address has only an "id" and a "street".

Ext.define('My.Model', {
extend : 'Ext.data.Model',
fields : [ "id", "name", ...],
hasOne : [ {
name : 'address',
model : 'Address',
associationKey : 'address'
} ]

I have a store for this model and the "address" object gets populated correctly. But I have a form in which I want to create a Model so after I create the form I do this:

var model = Ext.create('My.Model');

One of the fields in my form is a combo with all possible "address"-es:

xtype : 'combobox',
name : 'address.id',
store : 'AddressStore' }

And everyhing works, except that when I submit the form I get a JSON which looks like this:

{ "address.id" : 1 }
and not what I want:

{ "address" : {"id": 1} }

Here's how I submit the form:

var form = this.up('form').getForm();
var record = form.getRecord();
var values = form.getValues();


And then I send the data using an ajax call with parameters like this:

params : {data: Ext.JSON.encode(record.data)}

30 Jul 2014, 6:44 PM
The writer does not support nested data. You would need to send the data separately and have the server handle the related data.