• 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
My FetchRequest is not aware of changes I made
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

My FetchRequest is not aware of changes I made


  • Subject: My FetchRequest is not aware of changes I made
  • From: Martin <email@hidden>
  • Date: Tue, 12 Feb 2008 12:49:43 +0100

Hi,

Let Foo and Bar be two entities of my Core Data app. There is a one-to- many relationship between the two of them, Foo have bars and each Bar has a foo:
Foo Bar
bars <--->> foo


The Bar entity also has a boolean "isHappy" attribute.

Here is what I do:

- (IBAction)test:(id)sender {

NSError *error;
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:[NSEntityDescription entityForName:@"Foo" inManagedObjectContext:managedObjectContext]];
[request setPredicate:[NSPredicate predicateWithFormat:@"ALL bars.isHappy = YES"]];

NSArray *results = [managedObjectContext executeFetchRequest:request error:&error];
NSLog(@"Found %d Foos with very happy Bars.", [results count]);

for (NSManagedObject *foo in results)
for (NSManagedObject *bar in [foo mutableSetValueForKey:@"bars"])
[bar setValue:[NSNumber numberWithBool:NO] forKey:@"isHappy"];
}


Let's say that there are 3 Foos when my app launches, each of this Foos have happy bars.

When test: is first called, the log says:
"Found 3 Foos with very happy Bars."
Then all the isHappy attributes are changed to NO, which is instantly visually verified in the GUI (the checkboxes get unchecked).


But if I call test: again, the log says:
"Found 3 Foos with very happy Bars."

Why doesn't the fetch request finds 0 Foos? Why isn't the fetch request aware of the changes just made when the GUI is?
The only thing that makes it work is to save the context after doing the changes, but I don't want to save at that point.


This behaviour seems to go completely against the documentation: "If an object in a context has been modified, a predicate is evaluated against its modified state, not against the current state in the persistent store."

Thanks,
Martin.


_______________________________________________

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: My FetchRequest is not aware of changes I made
      • From: William Turner <email@hidden>
  • Prev by Date: How to implement incremental search like Safari using WebView?
  • Next by Date: Re: Binding NSArrayController to program
  • Previous by thread: Re: How to implement incremental search like Safari using WebView?
  • Next by thread: Re: My FetchRequest is not aware of changes I made
  • Index(es):
    • Date
    • Thread