Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re: More CoreData questions...



Mike,

When I get to the first table that I need to recreate a one-to many relationship I find that if after specifying the first connection if I don't force a save of the managedObjectContext then the next fetch that is for the index comes up with 0 results. Here is part of my
code...

It's a little hard to tell from the code excerpt that omits the definition of the fetch request, the relationships involved, etc. but my guess is that you're encountering a limitation of the in memory filtering that is applied to uncommitted changes.


The -initWithEntity:insertIntoManagedObjectContext: method creates a new instance that is added to the list of pending insertions. Those are committed during the next save.

Executed a fetch request always goes to disk (searches the database) but the newly inserted objects haven't actually been saved yet. So the database returns 0 results. The NSManagedObjectContext notices it has a bunch of unsaved changes, and tries to adjust the results from the database query to accommodate the changes that have not yet been committed.

This adjustment is done by applying the same predicate from the fetch request to each dirtied (unsaved) managed object of the entity you're fetching. If the predicate matches the unsaved changes then inserted objects are added to the result set, deleted objects removed, etc.

Since the filtering is only done to managed objects of the entity you're fetching, it's possible to fail to notice that changes to related objects would have affected the predicate.

I infer from the excerpt that you're fetching Teachers. The teacher objects ought to be marked dirty by:
[t1 addClasses_TaughtObject:c];


so examining your fetch request and your custom setter code would be helpful.
--

-Ben
_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.