Skip to content

Commit

Permalink
pushRetrieve now updates primaryKey value of record + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mauritslamers committed Jun 30, 2011
1 parent 8c709f9 commit 9b339d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions frameworks/datastore/system/store.js
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions frameworks/datastore/tests/system/store/pushChanges.js
Expand Up @@ -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
});

0 comments on commit 9b339d8

Please sign in to comment.