Results 1 to 2 of 2

Thread: Mapping form to a nested model

  1. #1
    Sencha User
    Join Date
    Jul 2014
    Posts
    2

    Default Mapping form to a nested model

    Hello,

    I have a simple model with some "hasOne" associations. Here the address has only an "id" and a "street".
    Code:
    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:
    Code:
    var model = Ext.create('My.Model');
            form.loadRecord(model);
    One of the fields in my form is a combo with all possible "address"-es:
    Code:
    {
         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:
    Code:
    { "address.id" : 1 }
    and not what I want:
    Code:
    { "address" : {"id": 1} }
    Here's how I submit the form:
    Code:
    var form = this.up('form').getForm();
    var record = form.getRecord();
    var values = form.getValues();
    
    
    record.set(values);
    And then I send the data using an ajax call with parameters like this:
    Code:
    params : {data: Ext.JSON.encode(record.data)}

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,409
    Answers
    716

    Default

    The writer does not support nested data. You would need to send the data separately and have the server handle the related data.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •