                 if property.type == PropertyType.object {
                     if let target = object?.value(forKey: property.name) as? Object {
                         
-                        let targetIdentifier = target.value(forKey: objectClass.primaryKey()!) as! String
+                        let targetIdentifier = self.getStringIdentifier(for: target, usingPrimaryKey: primaryKey)
                         let referenceIdentifier = "\(property.objectClassName!).\(targetIdentifier)"
                         let recordID = CKRecord.ID(recordName: referenceIdentifier, zoneID: zoneID)
                         // if we set the parent we must make the action .deleteSelf, otherwise we get errors if we ever try to delete the parent record

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

        }
    }
    
    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)
