1
votes

I was wondering about this problem lately. I am concerned about long-term problems with the given implementation of Core Data below.

Lets say we have a Task NSManagedObject that has one-to-one relationship to Album object with Nullify delete rule both ways. Then Album has one-to-many relationship to Photo object with same delete rule.

The question is theoretical. What happens if Task object gets deleted, but developer doesn't delete Album and Photo objects related to Task manually? Is there a possibility of the data corruption this way? Or will Core Data will just grow in size and not complain?

Thank you for your help beforehand.

1

1 Answers

2
votes

What happens if Task object gets deleted, but developer doesn't delete Album and Photo objects related to Task manually?

Then normal "nullify" behavior applies. The inverse relationship from Album to Task is set to nil, but nothing else changes. With "nullify" that's all that ever happens, relationships are set to nil when the related object is removed.

Is there a possibility of the data corruption this way?

Well, you get an Album with no associated Task. Whether that would be considered corrupt depends on your specific requirements. If every Album must have a Task then you'd probably consider it corrupt. On the other hand if this relationship is optional, then having it be nil is fine. The underlying persistent store file (probably SQLite) is no more likely to be corrupted in this case than in any other case.

Or will Core Data will just grow in size and not complain?

Deleting managed objects won't make the persistent store file grow. If what you mean is, will the related Album and Photo objects still exist, then yes, because that's how the design you've described works. Whether that's a problem or not depends again on your specific requirements.