From 6f4377b5737d11aa7a75a807b3c35ae4b1ba2c8a Mon Sep 17 00:00:00 2001 From: Greg Fairbanks Date: Wed, 9 Jan 2013 14:43:02 -0500 Subject: [PATCH] Modified unregisterChildFromParent so it can safely be called on any storeKey, even if it is not a child record. --- frameworks/datastore/system/store.js | 26 +++++++++---------- .../models/nested_records/nested_record.js | 5 ++-- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/frameworks/datastore/system/store.js b/frameworks/datastore/system/store.js index 8377d7db93..932bd27f58 100644 --- a/frameworks/datastore/system/store.js +++ b/frameworks/datastore/system/store.js @@ -1364,7 +1364,7 @@ SC.Store = SC.Object.extend( /** @scope SC.Store.prototype */ { that.unloadRecord(null, null, storeKey, newStatus); }); - this.unregisterChildFromParent(storeKey, YES); + this.unregisterChildFromParent(storeKey); return this ; }, @@ -1561,26 +1561,26 @@ SC.Store = SC.Object.extend( /** @scope SC.Store.prototype */ { id = this.idFor(childStoreKey), that = this; - // Check the child to see if it has a parent + // Check the child to see if it has a parent childRecords = this.childRecords; - // Remove the parent's connection to the child. This doesn't remove the - // parent store key from the cache of parent store keys if the parent - // no longer has any other registered children, because the amount of effort - // to determine that would not be worth the miniscule memory savings. + // Remove the parent's connection to the child. This doesn't remove the + // parent store key from the cache of parent store keys if the parent + // no longer has any other registered children, because the amount of effort + // to determine that would not be worth the miniscule memory savings. oldPk = childRecords[childStoreKey]; if (oldPk) { delete this.parentRecords[oldPk][childStoreKey]; - } + } - // Remove the child. - // 1. from the cache of data hashes - // 2. from the cache of record objects - // 3. from the cache of child record store keys - this.removeDataHash(childStoreKey); + // Remove the child. + // 1. from the cache of data hashes + // 2. from the cache of record objects + // 3. from the cache of child record store keys + this.removeDataHash(childStoreKey); if (this.records) { delete this.records[childStoreKey]; - } + } delete childRecords[childStoreKey]; } } diff --git a/frameworks/datastore/tests/models/nested_records/nested_record.js b/frameworks/datastore/tests/models/nested_records/nested_record.js index 939db5f8d0..7e481e82e0 100644 --- a/frameworks/datastore/tests/models/nested_records/nested_record.js +++ b/frameworks/datastore/tests/models/nested_records/nested_record.js @@ -621,7 +621,7 @@ test("Reloading the parent record uses same child record.", function() { cacheLength = 0; for (key in store.records) { cacheLength += 1; } - equals(cacheLength, 3, 'there should be three records cached in the store'); + equals(cacheLength, 2, 'there should be two records cached in the store'); cacheLength = 0; for (key in store.dataHashes) { if (store.dataHashes[key] !== null) cacheLength += 1; } @@ -629,7 +629,7 @@ test("Reloading the parent record uses same child record.", function() { // Reload the record SC.RunLoop.begin(); - store.loadRecord(NestedRecord.ParentRecordTest, { + parentStoreKey = store.loadRecord(NestedRecord.ParentRecordTest, { name: 'Parent Name 3', info: { type: 'ChildRecordTest', @@ -640,6 +640,7 @@ test("Reloading the parent record uses same child record.", function() { parentId); SC.RunLoop.end(); + testParent3 = store.materializeRecord(parentStoreKey); child = testParent3.get('info'); equals(testParent3.get('status'), SC.Record.READY_CLEAN, 'parent status should be READY_CLEAN'); equals(child.get('status'), SC.Record.READY_CLEAN, 'child status should be READY_CLEAN');