Skip to content

Instantly share code, notes, and snippets.

@ColinCampbell
Created August 24, 2010 19:28
Show Gist options
  • Select an option

  • Save ColinCampbell/548152 to your computer and use it in GitHub Desktop.

Select an option

Save ColinCampbell/548152 to your computer and use it in GitHub Desktop.
From 9297ae9b2894fddc058d1822731ade9d2a4518c6 Mon Sep 17 00:00:00 2001
From: Colin Campbell <[email protected]>
Date: Tue, 24 Aug 2010 16:52:33 -0230
Subject: [PATCH] Fixed issue with SC.ManyArray not notifying inverse attributes of correct records that got removed in SC.ManyArray#replace, with tests.
---
frameworks/datastore/system/many_array.js | 2 +-
.../datastore/tests/models/many_attribute.js | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/frameworks/datastore/system/many_array.js b/frameworks/datastore/system/many_array.js
index 2e498fc..9c07d9a 100644
--- a/frameworks/datastore/system/many_array.js
+++ b/frameworks/datastore/system/many_array.js
@@ -232,7 +232,7 @@ SC.ManyArray = SC.Object.extend(SC.Enumerable, SC.Array,
if (toRemove) SC.ManyArray._toRemove = null; // reuse if possible
else toRemove = [];
- for(i=0;i<amt;i++) toRemove[i] = this.objectAt(i);
+ for(i=0;i<amt;i++) toRemove[i] = this.objectAt(idx + i);
}
// pass along - if allowed, this should trigger the content observer
diff --git a/frameworks/datastore/tests/models/many_attribute.js b/frameworks/datastore/tests/models/many_attribute.js
index fae8c22..ef8b51f 100644
--- a/frameworks/datastore/tests/models/many_attribute.js
+++ b/frameworks/datastore/tests/models/many_attribute.js
@@ -230,6 +230,17 @@ test("modifying a toMany array should mark the record as changed", function() {
});
+test("Modifying a toMany array using replace", function() {
+ var recs = rec.get('barToOne'),
+ objectForRemoval = recs.objectAt(1);
+
+ recs.replace(1, 1, null); // the object should be removed
+
+ ok(objectForRemoval !== recs.objectAt(1), "record should not be present after a replace");
+ equals(bar2.get('fooToOne'), null, "record should have notified attribute of change");
+});
+
+
test("modifying a toMany array within a nested store", function() {
var child = MyApp.store.chain() ; // get a chained store
--
1.7.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment