Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

pushRetrieve now updates primaryKey value of record + tests

  • Loading branch information...
commit 9b339d82ff48cb3bf55fce4bad7556fa1a5dcaca 1 parent 8c709f9
@mauritslamers authored
View
1  frameworks/datastore/system/store.js
@@ -2258,6 +2258,7 @@ SC.Store = SC.Object.extend( /** @scope SC.Store.prototype */ {
if(dataHash===undefined) this.writeStatus(storeKey, status) ;
else this.writeDataHash(storeKey, dataHash, status) ;
+ if (id && this.idFor(storeKey) !== id) SC.Store.replaceIdFor(storeKey, id);
this.dataHashDidChange(storeKey);
return storeKey;
View
16 frameworks/datastore/tests/system/store/pushChanges.js
@@ -59,3 +59,19 @@ test("Issue a pushError and check if there is conflicts", function() {
ok(!res, "There is a conflict, because of the state, this is expected.");
});
+test("A pushRetrieve updating the id of an existing record should update the primary Key cache", function(){
+ var tmpid, recFirst, recSecond, sK;
+
+ tmpid = "@2345235asddsgfd";
+ recFirst = { firstname: 'me', lastname: 'too', guid: tmpid };
+ recSecond = { firstname: 'me', lastname: 'too', guid: 1 };
+ SC.RunLoop.begin();
+ var sK = store.loadRecord(SC.Record, rec, tmpid);
+ SC.RunLoop.end();
+ equals(store.idFor(sK),tmpid); //check whether the id is indeed tmpid
+ SC.RunLoop.begin();
+ store.pushRetrieve(SC.Record,1,recSecond,sK);
+ SC.RunLoop.end();
+ equals(store.idFor(sK),1); // id should now have been updated
+});
+
Please sign in to comment.
Something went wrong with that request. Please try again.