2009-01-05 09:58:52.091 GitHub Chat[53339:10b] Illegal attempt to establish a relationship 'project' between objects in different contexts (source = <ProjectCommit: 0x800519a20> (entity: ProjectCommit; id: 0x8004bee80 <x-coredata:///ProjectCommit/t494E4AE7-C31C-4FEB-9B37-5DE6AAC9EEB85> ; data: {
comments = (
);
"commit_sha" = nil;
"commit_url" = nil;
desc = nil;
project = 0x8002bb820 <x-coredata://5298BFF3-D26C-4BF5-834B-BEF8F1205194/Project/p102>;
}) , destination = <Project: 0x8002eb820> (entity: Project; id: 0x8002bb820 <x-coredata://5298BFF3-D26C-4BF5-834B-BEF8F1205194/Project/p102> ; data: {
commits = (
0x8004bee80 <x-coredata:///ProjectCommit/t494E4AE7-C31C-4FEB-9B37-5DE6AAC9EEB85>
);
name = "rails/rails";
projectname = rails;
username = rails;
}))
In this case, you must create the ProjectCommit objects using the same
NSManagedObjectContext from which you fetched the Projects, otherwise
you can never connect the two.
Cheers,
Matt.
> So I can add + save, add + save, remove + save, using the same
> context?
Yes.
On 05/01/2009, at 11:22 AM, Dr Nic Williams wrote:
> When do I need another NSManagedObjectContext then?
If you're only accessing one SQLite file on disk? Almost never.
You need a separate context if you're working with a separate SQLite
files on disk. But if you have two files open at once, copying data
from one to the other must be done manually.
For example: multiple documents. If you want to copy and paste between
two NSPersistentDocuments (which are each backed by their own
NSManagedObjectContexts) you must serialize the copied objects from
the first NSManagedObjectContext yourself (using NSKeyedArchiver will
work but you must implement protocol methods) and then reconstruct
them yourself in the second NSManagedObjectContext.
There are less common situations where you may open the same SQLite
file in multiple contexts. Normally due to multi-threading. You should
never use the same context in multiple threads -- even if all threads
are just reading. To read from the same Core Data archive in multiple
threads, open a new NSManagedObjectContext in each thread -- and
perform all work independently.
Cheers,
Matt.