Skip to content

Commit 21d3543

Browse files
author
Colin Campbell
committed
Merge pull request sproutcore#535 from mauritslamers/empty
pushRetrieve now updates primaryKey value of record + tests
2 parents 936574c + 9b339d8 commit 21d3543

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Diff for: frameworks/datastore/system/store.js

+1
Original file line numberDiff line numberDiff line change
@@ -2258,6 +2258,7 @@ SC.Store = SC.Object.extend( /** @scope SC.Store.prototype */ {
22582258
if(dataHash===undefined) this.writeStatus(storeKey, status) ;
22592259
else this.writeDataHash(storeKey, dataHash, status) ;
22602260

2261+
if (id && this.idFor(storeKey) !== id) SC.Store.replaceIdFor(storeKey, id);
22612262
this.dataHashDidChange(storeKey);
22622263

22632264
return storeKey;

Diff for: frameworks/datastore/tests/system/store/pushChanges.js

+16
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,19 @@ test("Issue a pushError and check if there is conflicts", function() {
5959
ok(!res, "There is a conflict, because of the state, this is expected.");
6060
});
6161

62+
test("A pushRetrieve updating the id of an existing record should update the primary Key cache", function(){
63+
var tmpid, recFirst, recSecond, sK;
64+
65+
tmpid = "@2345235asddsgfd";
66+
recFirst = { firstname: 'me', lastname: 'too', guid: tmpid };
67+
recSecond = { firstname: 'me', lastname: 'too', guid: 1 };
68+
SC.RunLoop.begin();
69+
var sK = store.loadRecord(SC.Record, rec, tmpid);
70+
SC.RunLoop.end();
71+
equals(store.idFor(sK),tmpid); //check whether the id is indeed tmpid
72+
SC.RunLoop.begin();
73+
store.pushRetrieve(SC.Record,1,recSecond,sK);
74+
SC.RunLoop.end();
75+
equals(store.idFor(sK),1); // id should now have been updated
76+
});
77+

0 commit comments

Comments
 (0)