SyncKit icon indicating copy to clipboard operation
SyncKit copied to clipboard

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

Open sskjames opened this issue 4 years ago • 5 comments

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 avatar Jun 01 '21 07:06 sskjames

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 avatar Jun 02 '21 05:06 sskjames

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.

sskjames avatar Jun 03 '21 03:06 sskjames

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 avatar Jun 04 '21 14:06 mentrena

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

  • Were changes not detected in the parent entity or the child entity?
  • 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?

mentrena avatar Jun 20 '21 16:06 mentrena

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.

sskjames avatar Jun 21 '21 01:06 sskjames