1. #1
    Sencha Premium Member
    Join Date
    Mar 2012
    Posts
    2
    Vote Rating
    0
    bijulabalan is on a distinguished road

      0  

    Default Answered: Saving associated data

    Answered: Saving associated data


    I am trying to save a User Model with associated data products. Something like

    Ext.define('Test.model.User', {
    extend: 'Ext.data.Model',
    requires:'Test.model.Product',
    config: {
    fields: [
    {name: 'id', type: 'int'},
    {name: 'name', type: 'string'}
    ],
    hasMany: {model: 'Test.model.Product', name: 'products', associationKey: 'products'},


    proxy: {
    type: 'ajax',
    url : 'users.json',
    reader: {
    type: 'json',
    root: 'users'
    }
    }
    }
    });
    Ext.define('Test.model.Product', {
    extend: 'Ext.data.Model',
    config: {
    fields: [
    {name: 'id', type: 'int'},
    {name: 'total', type: 'float'},
    {name: 'status', type: 'string'}
    ]
    }
    });


    How do I post the changes to User and Product model in one call? When I call User.save, only the user related data is being sent. Do I to make a separate call to send the product data? I would like to get one json string that contains all the data that can be submitted through the ajax call.

    Thanks,
    Bijula

  2. 2.1.0 will have the ability to save associated data, currently it's not well supported.

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,547
    Vote Rating
    873
    Answers
    3566
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    2.1.0 will have the ability to save associated data, currently it's not well supported.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha Premium Member
    Join Date
    Mar 2012
    Posts
    2
    Vote Rating
    0
    bijulabalan is on a distinguished road

      0  

    Default


    Looks like a custom writer is the only solution for now. Thanks for the heads up!

  5. #4
    Sencha User
    Join Date
    Nov 2012
    Posts
    14
    Vote Rating
    0
    pflopez is on a distinguished road

      0  

    Default


    Now that sencha 2.1.0 is out, how can we accomplish this?

    Thanks!

  6. #5
    Sencha User
    Join Date
    Nov 2012
    Location
    Netherlands
    Posts
    50
    Vote Rating
    1
    Answers
    6
    eastlander is on a distinguished road

      0  

    Default


    I do it manually like:

    Code:
    Ext.Ajax.request({
                url: 'IncidentalOrder/SaveIncidentalOrder',
                method: 'post',
                headers: {
                    'Content-Type': 'application/json;charset=utf-8'
                },
                params: JSON.stringify(record.getData(true)),
                scope: this,
                success: function (response) {
                    
                }
            });
    record.getData(true) gets my toplevel model with all child associations.