mentrena / SyncKit

Automatic CloudKit synchronization
https://mentrena.github.io/SyncKit/
MIT License
507 stars 59 forks source link

Local Realm changes not detected for entities with relationship which have Int primary keys #154

Open sskjames opened 3 years ago

sskjames commented 3 years ago

Hi,

SyncKit is just being integrated into our app which uses Realm as the local database. Whenever changes are made to the local Realm, CloudKitSynchronizer is called to sync with the CloudKit private db. However, I observed that only the "inserted" records are being synced. When I "update" or "delete" a record locally it's not getting synced.

But I observed a different behaviour when I delete and re-install the app. Data from CloudKit is downloaded to the local Realm as expected. Inserted, updated and deleted records are all getting synced as expected.

I couldn't recreate this problem with the Example app.

I'm not able to understand why I'm facing this behaviour. What is that I have missed or misconfigured? Can someone please throw some light on this?

Thanks in advance, James

sskjames commented 3 years ago

Got more clarity on the behaviour. I observed that local changes were not detected correctly for entities which have relationship and most of my entities have Integer primary key. Looks like this might be the reason.

When I made changes in entities which didn't have any relationship, they are synced as expected.

sskjames commented 3 years ago

Sync works as expected when String primary keys are used. Entities having Int primary keys and relationships are not synced as and when changes are detected.

Since we are planning to move to String primary keys, I'll close this issue.

mentrena commented 3 years ago

Thanks, I'll reopen to keep as a reminder. Now that I went through the trouble of supporting int primary keys I'd better make sure it works...

mentrena commented 3 years ago

Hey @sskjames I'm trying to reproduce the issue you described with int primary keys, could you clarify:

sskjames commented 3 years ago

Hi @mentrena,

Did you mean that when you insert object A, it gets synced correctly, but if you make further changes to A then those changes are not detected?

Yes, you are right.

Were changes not detected in the parent entity or the child entity?

I couldn't answer it convincingly. In most cases, I observed it to be the parent and in some cases, to be the child entity.