views:

113

answers:

2

I'm implementing core data in my iphone app. It has two entities. Entity1: LatestData Entity2: LatestDetailedData

LatestData has URL, publishedDate, heading LatestDetailedData has URL, NewsDescription, PublishedDate, Author

Both entities have same URL for a record. Both the entities are connected with inverse relation ship. And the relation ship is "delete->Cascaded"

What I want: If I remove a record in LatestData, I want the record with same URL in LatestDetailedData must also be deleted.

How?

A: 

when you create the entities you need to create the relationship too

LatestDetailedData * entity2 = [[NSEntityDescription insertNewObjectForEntityForName:@"LatestDetailedData" inManagedObjectContext:context]; 
entity1.lastestdetail=entity2;

if you are just relying on a URL field, then thats bad practice. Set up the relationship in coredata and the cascaded deletes will take care of themselves.

Andiih
But I'm populating both the entities at different instances.So, how to proceed further here.
Satyam svv
Assuming you populate entity1 first, when you populate entity2, find the enetity1 (with a predicate based on the url) and create the relationship. If you don't have relationships between the entities that coredata knows about, you wont get cascaded deletes etc to work at all.
Andiih
A: 

If I am understanding you correctly, you are using a relationship and it has an inverse. If that is the case then when you delete one then Core Data will automatically delete the other and you don't need to do anything extra.

What are you seeing that suggests that is not happening?

Update

Since you are using multiple threads, are you using one NSManagedObjectContext per thread? If so, are you updating all of the threads when a save occurs? I suspect one of those two is not occurring and therefore causing your issue.

Marcus S. Zarra
sorry, i didn't update previously that i'm populating both the entities at different instances from different threads.when i'm deleting in one entity, then reocrd in other entity with same URL is not deleting at all.
Satyam svv