Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clone parent data hash when making nested data editable #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions packages/sproutcore-datastore/lib/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,29 @@ SC.Store = SC.Object.extend( /** @scope SC.Store.prototype */ {
*/
readEditableDataHash: function(storeKey) {
// read the value - if there is no hash just return; nothing to do
var ret = this.dataHashes[storeKey];
var pk, pr, path, ret = this.dataHashes[storeKey];
if (!ret) return ret ; // nothing to do.

// clone data hash if not editable
var editables = this.editables;
if (!editables) editables = this.editables = [];
if (!editables[storeKey]) {
pk = this.childRecords[storeKey];
if (pk) {
// Since the is a nested record we have to actually walk up the
// parent chain to get to the root parent and clone that hash. And
// then reconstruct the memory space linking.
this.readEditableDataHash(pk);
pr = this.parentRecords[pk];
if (pr) {
path = pr[storeKey];
ret = this.dataHashes[storeKey] = path ? SC.getPath(this.dataHashes[pk], path) : null;
}
}
else {
ret = this.dataHashes[storeKey] = SC.copy(ret, YES);
}
editables[storeKey] = 1 ; // use number to store as dense array
ret = this.dataHashes[storeKey] = SC.copy(ret, YES);
}
return ret;
},
Expand Down