Skip to content

Commit 3816347

Browse files
temaputdavimacedo
andauthored
Fix cascadeSave=false bug (#1078)
* fix bug when saving with cascadeSave: false On SDK 2.11 saving new objects with option cascadeSave=false returns object without id (id = undefined). Rationale: _handleSaveResponse -> _migrateId demands _localId AND serverId to be defined _localId is generated with _getId() normally _getId() is called in object.save() method by calling unsavedChildren() but when cascadeSave=false unsavedChildren is not called -> _localId is undefined -> migrateId does not save serverId from created object Solution: since _localId is needed in controller.save() method, just call _getId() there * Update ParseObject.js * remove trailing space * add test Co-authored-by: Antonio Davi Macedo Coelho de Castro <adavimacedo@gmail.com>
1 parent d4ef3d6 commit 3816347

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/ParseObject.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2353,8 +2353,10 @@ const DefaultController = {
23532353
});
23542354

23552355
} else if (target instanceof ParseObject) {
2356-
// copying target lets Flow guarantee the pointer isn't modified elsewhere
2356+
// generate _localId in case if cascadeSave=false
2357+
target._getId();
23572358
const localId = target._localId;
2359+
// copying target lets Flow guarantee the pointer isn't modified elsewhere
23582360
const targetCopy = target;
23592361
const task = function() {
23602362
const params = targetCopy._getSaveParams();

src/__tests__/ParseObject-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2936,4 +2936,21 @@ describe('ParseObject pin', () => {
29362936
expect(error).toBe('Parse.enableLocalDatastore() must be called first');
29372937
}
29382938
});
2939+
it('gets id for new object when cascadeSave = false and singleInstance = false', (done) => {
2940+
ParseObject.disableSingleInstance();
2941+
CoreManager.getRESTController()._setXHR(
2942+
mockXHR([{
2943+
status: 200,
2944+
response: {
2945+
objectId: 'P5',
2946+
}
2947+
}])
2948+
);
2949+
const p = new ParseObject('Person');
2950+
p.save(null, {cascadeSave: false}).then((obj) => {
2951+
expect(obj).toBe(p);
2952+
expect(obj.id).toBe('P5');
2953+
done();
2954+
});
2955+
})
29392956
});

0 commit comments

Comments
 (0)