I've got two objects in my data model, say Class and Teacher. Class has a to-one relation to a Teacher and Teacher has a to-many back to Class.

When a Class is created I assign a particular default Teacher to it (e.g. J. Doe). Then, J. Doe has that class added to his set of Classes. I override [Class setTeacher:] to change a nil Teacher to the default Teacher.

- (void)setTeacher:(Teacher *)teach
{
        if (teach == nil)
                // from my NSManagedObjectContext extensions
teach = (Teacher *)[[self managedObjectContext] fetchOne:@"Teacher" whose:@"name" is:@"J. Doe" createIfNone:NO];

        [self willChangeValueForKey:@"teacher"];
        [self setPrimitiveValue:teach forKey:@"teacher"];
        [self didChangeValueForKey:@"teacher"];
}

This works great and every class starts with J Doe and if a Class's Teacher is set to nil, then it gets J Doe (who works very hard). There is, of course, one small problem that happens when a Teacher is remove:'d from the object model. The Delete Rule for Teacher.Class is set to Nullify. When a Teacher is removed, all of it's Classes get their Teacher set to null, which is overridden in setTeacher: so each Class gets J Doe for its Teacher. The problem is that this is not reflected in Teacher -- the Class is not added to the J Doe's set of Classes.

Bottom line:When a Teacher is remove:'d, its Classes get sent a setTeacher:nil (because the Delete Rule is Nullify). The nil gets changed to J Doe, so the Class points to J Doe. But J Doe is not updated to point back to Class.

Am I not supposed to modify the object graph during a remove:? Or, is this a bug in Delete Rule handling that I should submit? Or, did I miss something in the docs about this situation?

Thanks.

        john
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to