views:

76

answers:

1

Hi, I have the following data model and i want to break the many-to-many relationship between EntityA and EntityB. I'm doing this by removing EntityC object that connects both of them. I found that EntityA still have a relationship with EntityB although I saved the managed object context, I can see the changes take affect after EntityA records are re-fetched from database. Is there something I'm missing? Thanks in advance,Sarah

alt text

+1  A: 

I agree with the comment from Barry, from your description it sounds like you are using more than one NSManagedObjectContext and that will definitely cause an issue.

Is this a multi-threaded application?

Did you base this off of one of the Apple examples?

update

Referental integrity is the mostly likely cause of this issue. When you delete A, the relationship to C, from C's point of view may not be cleared immediately because Core Data does that kind of clean up either at the end of the run loop or at the next save. This means if you are peeking at the value before either of those occur, the relationship may be there. Are you look at the relationship immediately or is it hanging around a while late, i.e. after a save?

update

In your original question you stated that after the save EntityA still has a relationship to EntityB. Is this a typo? According to your model EntityA and EntityB do not have a direct relationship. Can you clarify?

or perhaps show the code where you delete EntityC and where you see EntityA having a relationship with EntityB.

Marcus S. Zarra
Yes I'm using the same NSManagedObjectContext and it works with the one-to-many relationship, I remove the object like [ entityAObject removeEntityCObject:entityCObject]; I thought this would break the relationship.should I delete entityCObject object from theNSManagedObjectContext as well.Thanks for your reply,
Sarah
I'm hanging around a while and doing some navigation after saving the changes. Actually the changes does not take place until I restart the application I thought because it re-fetches the records then.
Sarah
yes EntityA and EntityB don't have a direct relationship. I delete EntityC like that :[entityAObject removeEntityCObject:entityCObject]; and I see the relationship like that :NSLog([entityAObject.entityCObject entityCName]);
Sarah
And what does the '-removeEntityCObject:' method do? Is it only calling through to '-[NSManagedObjectContext removeObject:]'? Have you walked it with a debugger?
Marcus S. Zarra