Results 1 to 5 of 5

Thread: Saving associated data

  1. #1
    Sencha Premium Member
    Join Date
    Mar 2012
    Posts
    2
    Vote Rating
    0
      0  

    Default 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 User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,029
    Answers
    3976
    Vote Rating
    1368
      0  

    Default

    2.1.0 will have the ability to save associated data, currently it's not well supported.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  4. #3
    Sencha Premium Member
    Join Date
    Mar 2012
    Posts
    2
    Vote Rating
    0
      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
      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
    Answers
    6
    Vote Rating
    1
      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.

Posting Permissions

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