• 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
Re: Calling processPendingChanges from awakeFromInsert
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling processPendingChanges from awakeFromInsert


  • Subject: Re: Calling processPendingChanges from awakeFromInsert
  • From: Tony Becker <email@hidden>
  • Date: Thu, 20 Sep 2007 16:32:10 -0400

Until the awakeFromInsert is finished, the object is "incomplete"
Calling processPendingChanges flushes (effectively commits) this incomplete object to the DB (thats a bad thing)
Then, after awakeFromInsert, the real object is inserted, which appears as a dupe.


You must not call processPendingChanges in awakeFromInsert or awakeFromFetch.
For the same reasons, you can't call executeFecthRequest (which calls processPendingChanges), in either of the same awake methods.


Under various conditions, you'll get two objects - and have really strange undo problems (even if you don't call the undo registration code), which I suspect you're having.

Call your undo registration code after the object is inserted into the context.

On Sep 20, 2007, at 4:13 PM, Michael Burns wrote:

Hello list,

I'm having a strange problem while trying to set a value for an NSManagedObject in its "awakeFromInsert" method. The code is as follows:

- (void)awakeFromInsert
{
    [super awakeFromInsert];

	NSManagedObjectContext* moc = [self managedObjectContext];

	// don't allow this new object to be undone
	[moc processPendingChanges];

[[moc undoManager] disableUndoRegistration];

[self performSelector:@selector(setUniqueProject) withObject:nil afterDelay:0];


	// turn the undo manager back on
	[moc processPendingChanges];
	[[moc undoManager] enableUndoRegistration];
}

The object is inserted by pressing a button binded to an NSArrayController who's set is binded to an NSTableView. The problem is that when I run this code as is, it creates two identical objects in the table view. If I comment out the two [moc processPendingChanges] lines, the problem goes away but then (of course) I can undo the actions in "setUniqueProject" and that is not good.

Maybe there is an easier way to go about this entirely (I just want to set the "Project" relationship of this object to the current project when it is created ... can this really be that complicated?)

Thanks!
Mike
_______________________________________________

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

_______________________________________________

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


  • Follow-Ups:
    • Core Data guidance Was: Calling processPendingChanges from awakeFromInsert
      • From: Brian Williams <email@hidden>
References: 
 >Calling processPendingChanges from awakeFromInsert (From: Michael Burns <email@hidden>)

  • Prev by Date: Calling processPendingChanges from awakeFromInsert
  • Next by Date: Re: Calling processPendingChanges from awakeFromInsert
  • Previous by thread: Calling processPendingChanges from awakeFromInsert
  • Next by thread: Core Data guidance Was: Calling processPendingChanges from awakeFromInsert
  • Index(es):
    • Date
    • Thread