6

How does .DeleteSelf really work? Docs says:

When the reference object’s action is set to CKReferenceActionDeleteSelf, the target of the reference—that is, the record stored in the reference’s recordID property—becomes the owner of the source record. Deleting the target (owner) record deletes all its source records.

but my impression is that deleting a target will not always delete source. And it is quite annoying when it remains in the container, client downloads it, and expect that the reference point to somewhere, but target does not exist when building up slice of the server data store on client?

How do you treat this case? You ignore that sort of records? Or periodically you look up the CloudKit storage, searching for corrupt records to delete them?

Or instead of deleting a record is it better to set an attribute that it is in a deleted state, but keep it in the database?

János
  • 32,867
  • 38
  • 193
  • 353
  • You should be able to rely on the .DeleteSelf. If it does not work, then you should create a bug report at http://bugreport.apple.com If you do want to create a workaround for this bug and since you are in control of what happens on the moment you are removing a record I think it would be best to also manually remove all related records at that same moment. – Edwin Vermeer Sep 27 '15 at 08:28
  • I'm also seeing intermittent behaviour with .DeleteSelf – Michael Waterfall Oct 27 '15 at 11:46
  • I'm running into this issue. I have several tables with a one-to-many relationship to a master table. In the public database, I add the master record and then some records in the other tables. If this is all done from one user and no other users even accesses the data, then deleting the master record results in all of the other records being deleted as expected. But once another user accesses the data, then the cascade delete doesn't happen and only the master record is deleted. Seems pointless if you can't count on this feature. – rmaddy Apr 27 '16 at 22:42

2 Answers2

2

I just struggled with this one for a while and I thought I would share my findings...

It is fundamentally a permission issue. The cascading delete will only work if the user deleting the records has 'write' permissions to all the records needing to be deleted. So in the CloudKit Dashboard, the cascading delete will only work for the records created with the developer's iCloud account.

If you need to delete records that don't belong to the user deleting them, you can add 'write' permissions for a Record Type under Security.

enter image description here

Yann Bodson
  • 1,634
  • 1
  • 17
  • 29
  • My records are in the same zone created by the same user and references still don't get deleted. I think it's a bug in the CloudKit Dashboard. And yes, it's still happening in late 2017. :) – Clifton Labrum Sep 06 '17 at 21:40
0

If you are deleting via CloudKit Dashboard you have to wait before switching record types to check the other end of the reference. More than likely you switched before the delete actually happened. You can use Safari's Web Inspector on the Network tab to check when the delete has actually finished. It takes a very long time to delete multiple records.

malhal
  • 26,330
  • 7
  • 115
  • 133