• 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: Mike Burns <email@hidden>
  • Date: Thu, 20 Sep 2007 18:32:12 -0400


On Sep 20, 2007, at 6:18 PM, Jim Correia wrote:

It sounds like the project is a document singleton/global. That the objects need to access its properties still don't sound like a compelling or correct reason to model a relationship between WBObject and Project and pay the cost of maintaining those relationships and their inverses. If this is the case, you should just fetch the Project directly and use it when you need it. This has the side effect that it also eliminates the problem you are having about (but you should still understand why your code is wrong before you delete it.)


Jim

You make some good points there, and after reevaluating my code I can see how getting rid of that project relationship would make more sense for my purposes. (I have other managed objects like the WBObject with that same relationship and the same goes for them.) But in the interest of figuring out what isn't working, I remember why I asked that question in the first place. The following code creates the same problem that "processPendingChanges" seemed to cause in the first place (duplicating the newly created object):


- (void)awakeFromInsert
{
    [super awakeFromInsert];

	NSManagedObjectContext* moc = [self managedObjectContext];
	NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSError *fetchError = nil;
    NSArray *fetchResults;

@try
{
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Project" inManagedObjectContext:moc];
[fetchRequest setEntity:entity];
fetchResults = [moc executeFetchRequest:fetchRequest error:&fetchError];
}
@finally
{
[fetchRequest release];
}


if ((fetchResults != nil) && ([fetchResults count] == 1) && (fetchError == nil))
{
[self setValue:[fetchResults objectAtIndex:0] forKey: @"project"];
}


    if (fetchError != nil)
	{
        [self presentError:fetchError];
    }
    else
	{
        // should present custom error message...
    }
}

Does executing a fetch request cause that same problem? And if so, what is the best work around?

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


  • Follow-Ups:
    • Re: Calling processPendingChanges from awakeFromInsert
      • From: Jim Correia <email@hidden>
References: 
 >Calling processPendingChanges from awakeFromInsert (From: Michael Burns <email@hidden>)
 >Re: Calling processPendingChanges from awakeFromInsert (From: Jim Correia <email@hidden>)
 >Re: Calling processPendingChanges from awakeFromInsert (From: Michael Burns <email@hidden>)
 >Re: Calling processPendingChanges from awakeFromInsert (From: Jim Correia <email@hidden>)
 >Re: Calling processPendingChanges from awakeFromInsert (From: Mike Burns <email@hidden>)
 >Re: Calling processPendingChanges from awakeFromInsert (From: Jim Correia <email@hidden>)

  • Prev by Date: Re: Calling processPendingChanges from awakeFromInsert
  • Next by Date: Re: Cocoa Books
  • Previous by thread: Re: Calling processPendingChanges from awakeFromInsert
  • Next by thread: Re: Calling processPendingChanges from awakeFromInsert
  • Index(es):
    • Date
    • Thread