-
6 May 2012 5:40 PM #1
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
-
Best Answer Posted by mitchellsimoens
2.1.0 will have the ability to save associated data, currently it's not well supported.
-
9 May 2012 9:11 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,716
- Vote Rating
- 439
- Answers
- 3113
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
________________
http://www.JSONPLint.com - Source to lint your JSONP!
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 almost in print!
When posting code, please use BBCode's CODE tags.
-
11 May 2012 5:26 AM #3
Looks like a custom writer is the only solution for now. Thanks for the heads up!
-
6 Dec 2012 11:00 AM #4
Now that sencha 2.1.0 is out, how can we accomplish this?
Thanks!
-
6 Dec 2012 11:54 PM #5
I do it manually like:
record.getData(true) gets my toplevel model with all child associations.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) { } });


Reply With Quote