• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
CoreData object graph gets confused
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CoreData object graph gets confused


  • Subject: CoreData object graph gets confused
  • From: John Terranova <email@hidden>
  • Date: Mon, 10 Aug 2009 15:48:39 -0700

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 (email@hidden)

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:
This email sent to email@hidden


  • Prev by Date: Registering and opening a help book located outside an application bundle
  • Next by Date: Re: Trouble with event taps...
  • Previous by thread: Registering and opening a help book located outside an application bundle
  • Next by thread: [MEET] CocoaHeads-NYC meeting Thu 08/13
  • Index(es):
    • Date
    • Thread