re: More CoreData questions...
re: More CoreData questions...
- Subject: re: More CoreData questions...
- From: Ben Trumbull <email@hidden>
- Date: Tue, 15 Jan 2008 18:20:59 -0800
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:
This email sent to email@hidden