What is the best pattern/practice for saving nested data in ExtJs 4?
This question is related to my other posts:
I am going to use a simple example: Order & Line Items defined as two models, with Order having one or more Line Items.
The main requirement is this: when I save the Order and its Line Items, they have to be saved as one transaction.
In ExtJs 3 I would define two stores, one for the Order and one for Line Items, I would do an ajax call passing the data from both to a server controller method, and then, on the server side (I use Ext.Net), I would save them in the db using one transaction. This pattern works in ExtJs 4 as well.
Now, in ExtJs 4 we have models that are capable of having relationships :-) so, instead of two stores, I have one store with a HasMany relationship, an Order has many Line Items.
I sort of expected that I can save an Order, and when I save the order, the data from its Line Items models is included as well. That is not what happens from what I've seen debugging store.sync() calls.
One of the things that is not clear to me is how the proxy api calls work as individual http requests in the context where the requirement is that all the row changes (including changes in their associated data) have to be saved as one unit. I guess one could implement the server request handlers to temporarily store the data on the server side, and then when the batch completes, one more call has to be made to persist the data as one unit in a database.
Another idea I tried is to get all the data from the store (including child data) and resolve all the changes on the server side (it is better to do it there anyway just because the data on the client could become stale sooner). There seems to be no extjs method that extracts the store data and follows the HasMany relationships. Something like Writer.getRecordData() that would follow the nested data.
And, as I said, another problem that I see is that, when the child changes, the parent is not marked as dirty, and even if it did, the Writer doesn't seem to include the children in the request that is sent to the server.
Any ideas, comments?
Update: Ext.Net has implemented an nice Store API method, getChangedData, that extracts all the changes from a store (not including the nested data though). This allows saving all the row changes in a store (again, not including the children) in one server call.