         }
     }
     
+    func getObjectIdentifier(stringObjectId: String, entityType: String) -> Any? {
+        let objectClass = realmObjectClass(name: entityType)
+        guard let schema = objectClass.sharedSchema(),
+              let keyType = schema.primaryKeyProperty?.type else {
+            return nil
+        }
+        
+        switch keyType {
+        case .int:
+            return Int(stringObjectId)!
+        case .objectId:
+            return try! ObjectId(string: stringObjectId)
+        case .string:
+            return stringObjectId
+        default:
+            return stringObjectId
+        }
+    }
+    
     func syncedEntity(for object: Object, realm: Realm) -> SyncedEntity? {
         
         let objectClass = realmObjectClass(name: object.objectSchema.className)

        let record = getRecord(for: syncedEntity) ?? CKRecord(recordType: syncedEntity.entityType, recordID: CKRecord.ID(recordName: syncedEntity.identifier, zoneID: zoneID))
        
        let objectClass = realmObjectClass(name: syncedEntity.entityType)
        let objectIdentifier = getObjectIdentifier(for: syncedEntity)
        let object = realmProvider.targetRealm.object(ofType: objectClass, forPrimaryKey: objectIdentifier)
        let entityState = syncedEntity.state

            }
            
            let targetObjectClass = realmObjectClass(name: className)
            let targetObjectIdentifier = getObjectIdentifier(stringObjectId: relationship.targetIdentifier, entityType: className)
            let targetObject = realmProvider.targetRealm.object(ofType: targetObjectClass, forPrimaryKey: targetObjectIdentifier)
            
            guard let target = targetObject else {
                continue
