Many-to-one relationship can't be unlinked

I am using NSPersistentCloudKitContainer, and have a many-to-one optional relationship, let say many "item" to one "project".


This relationship is optional, so I can do this ->

item.project = nil

when the user decided that this item does not belongs to any project.


This code is fine in Core Data, and the inverse relationships are updated accordingly.


However, once this gets synced to CloudKit, and come back down, the "project relationship" will be restored. Setting the project to other entities are fine, it just cannot be set to "nil".


Playing with the CloudKit dashboard, I realized that the schema that is created have a CD_Project as String. If I create a new item without any project, there's no such field, however, once I assign a project to an item, the field is set, and there is no way to unset this field, even from the CloudKit Dashboard. I naively tried to clear out the string in cloudkit dashboard but it crashes my app when the sync happens.


Is this a bug that will be fixed? The issue is also posted by another developer here:

https://stackoverflow.com/questions/57470636/relationship-persistence-with-nspersistentcloudkitcontainer


I have a few workaround ideas but they all require extra work, and seems to confuse readers of the code in the future:

1. change it to many-to-many instead

2. have a special project that means "No Project"

3. have a field in item named "projectIsNil"

Have you found any solution to this problem? I've the same issue with a one-to-many relationship which is managed correctly in Core Data but is not synced on iCloud and at the next restart the relationship is restored.

Same problem here. Did you ever find a proper solution?

iOS 14 seems to have fixed this.
Many-to-one relationship can't be unlinked
 
 
Q