When I save a model with a hasmany property, the model is updated on the server correctly. But when the model is interpreted by the EXTJS the child relations are not updated correctly.

After some debugging, I found that the Ext.data.Operation method uses the commitRecords method to copy the server record to the client record.
The server record is OK, but the client record doesn´t have its child’s updated after the copyFrom method.

It first delete the associated store, then it creates a new one and finally it populates the store with server data.

The creation of a new store seems necessary when creating new records because the store has a filter that need to be updated with server data.
Initially, the hasManyStore has a filter {property: pkey, value: null}
After the record has been saved, it will have a pkey, so the filter must be updated.
So this line
association.createStore().call(this);
avoid the duplication of
Ext.data.association.HasMany#createStore

Hope this helps

24 Apr 2013, 12:08 AM

Drömbolaget

Another version of copyFrom that loads associated data

I too stumbled upon this problem. This is the version we're using now. it's a bit better in that it doesn't unnecessarily delete the store or existing records if not needed. Might help someone who expects save() on a model to update associated records from server response too.

var storeName = association.storeName;
if (typeof (me[storeName]) === 'undefined') {
me[storeName] = Ext.clone(sourceRecord[storeName]);
}
// We don't want to replace the store if it already exists as it could have events bound already
else {
// The result could be without the store entirely since the server deemed nothing changed.
// If the server want's to tell us that all items in the association have been removed it must send an empty array in json response.
if (sourceRecord[storeName]) {
var
toAdd = [],
toRemove = [];