Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

pushRetrieve now updates primaryKey value of record + tests #535

Merged
merged 1 commit into from

2 participants

@mauritslamers
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.

@ColinCampbell ColinCampbell merged commit 21d3543 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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
+});
+
Something went wrong with that request. Please try again.