Skip to content
This repository

pushRetrieve now updates primaryKey value of record + tests #535

Merged
merged 1 commit into from almost 3 years ago

2 participants

Maurits Lamers Colin Campbell
Maurits Lamers
Collaborator

When pushRetrieve is used to update a record of which the primaryKey value has changed, it does not update the stores cache.
This behaviour can be reproduced as follows:

var sK = store.loadRecord(Model, { firstname: 'me', lastname: 'too', guid: '@433247823'}, '@433247823');
store.pushRetrieve(Model, 1, {firstname: 'me', lastname: 'too', guid: 1}, sK);
store.idFor(sK); // returns @4332478 instead of 1

The included patch solves this behaviour by mimicking the dataSourceDidComplete behaviour in updating the stores primaryKey value cache. A test is included.

Colin Campbell ColinCampbell merged commit 21d3543 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jun 30, 2011
Maurits Lamers mauritslamers pushRetrieve now updates primaryKey value of record + tests 9b339d8
This page is out of date. Refresh to see the latest.
1  frameworks/datastore/system/store.js
@@ -2258,6 +2258,7 @@ SC.Store = SC.Object.extend( /** @scope SC.Store.prototype */ {
2258 2258 if(dataHash===undefined) this.writeStatus(storeKey, status) ;
2259 2259 else this.writeDataHash(storeKey, dataHash, status) ;
2260 2260
  2261 + if (id && this.idFor(storeKey) !== id) SC.Store.replaceIdFor(storeKey, id);
2261 2262 this.dataHashDidChange(storeKey);
2262 2263
2263 2264 return storeKey;
16 frameworks/datastore/tests/system/store/pushChanges.js
@@ -59,3 +59,19 @@ test("Issue a pushError and check if there is conflicts", function() {
59 59 ok(!res, "There is a conflict, because of the state, this is expected.");
60 60 });
61 61
  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 +

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.