• 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: CoreData: Editing a model with XCode corrupts reflefive relationships [SOLVED]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CoreData: Editing a model with XCode corrupts reflefive relationships [SOLVED]


  • Subject: Re: CoreData: Editing a model with XCode corrupts reflefive relationships [SOLVED]
  • From: Frank Illenberger <email@hidden>
  • Date: Tue, 19 Jul 2005 00:58:05 +0200

Charilaos,

thanks for your code. It really fixes the problem!

Cheers

 Frank

has anybody already observed the following phenomenon?

I have an entity that uses a reflexive relationship for building a tree. Until now this relationship worked fine. But if I now add another isolated entity to my model, this relationship stops working. This means, that an object add to one side of the relationship is not automatically put into the other side. It seems as if the model file has been damaged because even if I revert to the old model state by pressing undo in the XCode model editor, the wrong behaviour stays. Only if I revert to a backup copy of my model file, the said relationship starts working again.



What does your model look like. Do you use any entity inheritance (called parent in the UI)?


I ran into a problem with a previous layout of my model, and filed a bug. I was able to work around it by modifying the model at runtime before passing it to the persistent store coordinator.

Jim



Yes, I am using entity inheritance. The base entity contains the reflexive relationship that gets damaged.

Does it only get damaged with regards to the subentity? If so, it is a well known problem, and it is the same one that Jim is talking about. Basically, the inverse relationship to a relationship that a subentity inherits from its parent is broken, and needs to be fixed at run-time when the model is set. My workaround, per an Apple engineer's suggestion, was to implement managedObjectContent in MyDocument to fix re-establish the connection as follows:
- (id)managedObjectModel
{
// This code is necessary to bypass a bug, upon which the inverse relationships
// of relationships that subentities inherit from their parents are not set properly.
NSManagedObjectModel *model = [super managedObjectModel];
NSArray *entities = [model entities];
NSEnumerator *en = [entities objectEnumerator];
NSEntityDescription *item = nil;
while (item = [en nextObject]) {
NSEntityDescription *parent = [item superentity];
if (parent != nil) {
NSDictionary *relationships = [item relationshipsByName];
NSDictionary *parentRelationships = [parent relationshipsByName];
NSEnumerator *en2 = [relationships keyEnumerator];
id key = nil;
NSRelationshipDescription *relationship = nil;
while (key = [en2 nextObject]) {
relationship = [relationships objectForKey:key];
NSRelationshipDescription *parentInverse = [[parentRelationships objectForKey:key] inverseRelationship];
if ([relationship inverseRelationship] == nil && parentInverse != nil) {
[relationship setInverseRelationship:parentInverse];
}
}
}
}
return model;
}


It is a generic solution, I haven't tested it much, hopefully it will be of some use to you. I believe Jim also has a test case with his work-around, that just fixes the particular entities involved. I tried to have the method run through the entire model and fix whatever could be broken. Use at your own risk of course.
What exactly did you change in the model at runtime to make it work?

Frank

Haris



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >CoreData: Editing a model with XCode corrupts reflefive relationships (From: Frank Illenberger <email@hidden>)
 >Re: [off-list] Re: CoreData: Editing a model with XCode corrupts reflefive relationships (From: Frank Illenberger <email@hidden>)
 >Re: [off-list] Re: CoreData: Editing a model with XCode corrupts reflefive relationships (From: Charilaos Skiadas <email@hidden>)

  • Prev by Date: Re: [off-list] Re: CoreData: Editing a model with XCode corrupts reflefive relationships
  • Next by Date: Re: [RESOLVED] [[NSBundle mainBundle] bundlePath] and trailng slashes...
  • Previous by thread: Re: [off-list] Re: CoreData: Editing a model with XCode corrupts reflefive relationships
  • Next by thread: CoreData: Getting the currently selected item
  • Index(es):
    • Date
    • Thread