2

I found a question very similar to mine here, but it was un-replied to and unanswered so I will try again.

I may be missing something in regards to cascade deletes and core data. I am used to cascade deletes working as designed in RDBMS apps but having issues with core data.

I have an object record that get's inserted into entity via an "add form" called modally from a table view. No problem.

In another session I will insert objects into a related details entity (many) where there is a common loadID attribute in both. No problem.

In another session, I will call up the original table view to view the parent "loads", and swipe-delete, save the context, and the parent load gets deleted from the one side entity. No problem, (except apparently details objects in a many side entity do not get removed)

When I open the sqlite data source with a db manager, I see the child records (pay detail items) are being orphaned. I have double and triple checked the cascade delete settings in the relationships. Have tried different entity relationship settings combinations, but nothing seems to get the many records to automatically delete along with the parent record.

If you can't define corresponding keys in core data, how does core data know what belongs to what when you operate in multiple sessions (contexts) adding child objects to the many-side entity?

I don't know if I'm doing something wrong or missing a vital step prior to inserting new child objects in the many table, or doing something wrong or missing a step when deleting the parent object.

But I would suggest all with cascade deletes set to open your data file and be sure there are not orphaned objects (records)

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user2616647
  • 131
  • 9
  • To add .. the parent table is called "LoadHeader". I notice in the "LoadPayDetails" entity (many child), an attribute called 'zLOADHEADER' was created and these are all null. I did not define such an attribute in the data model so core data must have done this. So am I somehow supposed to be putting a "LoadID" reference there when inserting? – user2616647 Aug 05 '13 at 19:27
  • Show a picture of your data model and tell which delete rules are where on each relationship. – Wain Aug 05 '13 at 21:00
  • I can put up an image but I'm unsure what good that's going to do. It shows what you'd expect to see in a one-to-many relationship. I have "cascade delete" turned on on both relationship attributes (one on each entity). – user2616647 Aug 05 '13 at 21:46
  • Both ends of the relationship are set to cascade? – Wain Aug 05 '13 at 21:48
  • Also, I've trashed the NSManagedObject files and rebuilt them but no help. I've tried both ends set to cascade and one set to cascade and the other to nullify. The result is the same either way. (Orphans left) Yes, they have the inverse set. – user2616647 Aug 05 '13 at 21:54
  • The relationships are set as inverse of each other yes? – Wain Aug 05 '13 at 21:55
  • I assume it has something to do with context and what is/is not in what context when "save context" is called. But if that is the case then why have back-end server level cascade delete option? – user2616647 Aug 05 '13 at 21:58

0 Answers0