You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 17, 2023. It is now read-only.
When creating new object in sync result function returns auto generated id that may be used to reference and obtain that specific object in the future. Once this object is synced actual value will be replaced with the server side id. Fact that object id is auto generated and that we replacing it later is causing a lots of issues and making entire sync really hard to understand.
Proposition
As solution sync users may just generate identifiers themselves (or use already existing fields that they know they are unique. Then sync framework should have option to specify function or field that will be used as id. Thanks to that users can use this ID's in other objects without worrying about swapping id or holding localy generated identifiers as separate fields.
How this will work
varobj={id:"1234325234",name:"Wojtek"}varidGenerator=function(object){returnobject.id;};// Suggestion to override methodsync.manage("test",{idGenerator: idGenerator},{},{});// We can reference ID at any time and assign that to different dataset.varref={testRef:object.id};// We save object and do not care about what's being returnedsync.doSave("test",obj);// Saving reference that has object ID. sync.doSave("testReference",ref);// This should work not matter if we are in sync with server or offflinesync.doRead("test",ref.testRef);
Additional requirements
In order for this to fully work we will also need to provide custom data handler that
will use the same obj.id as id instead of the generated mongo ObjectId.
I see this as the best pattern for the moment to work with the sync.
This will ensure that ID stays the same no matter if user is offline/online, data was synced etc.