Introduction:
I have two objects defined as a one-to-many relationship: A <<-------> B. The relation of B to A is called myAs and is the to-many relation with Nullify as the Delete rule. The inverse relationship between A and B is a one-to-one relationship with Cascade, typically Delete.
I applied validateForDelete in class B like this:
- (BOOL)validateForDelete:(NSError **)error { [super validateForDelete:error]; BOOL validDelete = FALSE; if ([self.myAs count] == 0) { validDelete = TRUE; } return validDelete; }
The purpose of this is to delete object B only if it has no more objects A (but always delete object B if it does not have any objects A). This validateForDelete works as intended if I check this check manually before saving: when deleting object B:
if ([b validateForDelete:NULL]) {
The problem I am facing is that deleting object B is cascaded from deleting object A. Users will not have access to objects B directly - they are created and deleted through objects A. Therefore, my rule is that objects B must be deleted. when there are no more, the object associated with it must be forcibly applied to object A - therefore, the cascade when deleted.
The problem is that when I delete object A, validateForDelete is called on object B due to the cascade. I get a resolved error: Unresolved error (null), (null), because I do not call validateForDelete manually.
Question (s):
How can I access the validateForDelete call from cascading deletion programmatically so that I can pass the error variable and / or process the validateForDelete result from FALSE?
If the foregoing is not possible, how do I handle this use case? Is there an even more practical way to achieve this?
Thanks in advance.
source share