project-imas / encrypted-core-data

v2.0 - iOS Core Data encrypted SQLite store using SQLCipher
Other
785 stars 236 forks source link

One to Many relationship not working/inconsistent #220

Closed sandeepjoshiaw closed 8 years ago

sandeepjoshiaw commented 8 years ago

onetomany

This is my Core Data model. Initially I add objects & relationships to all the three entities and then save. Immediately when I fetch, everything works fine. But, once I fetch address again and try to get a set of vehicles associated with one of the person, I get empty set instead of a set of vehicles associated to that person.

This is the code I have used to fetch.

NSEntityDescription *entityAddress = [NSEntityDescription entityForName:@"Addresses" inManagedObjectContext:self.managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:entityAddress];

NSArray *result = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];

if (error) {
    NSLog(@"Unable to execute fetch request.");
    NSLog(@"%@, %@", error, error.localizedDescription);

} else {
    NSLog(@"%@", result);
}

Addresses *address = [result objectAtIndex:0];
NSSet *vehicleList = address.person.vehicles;
if ([vehicleList count]<= 0) {
    NSLog(@"Error");
}
else{
    NSLog(@"%@",vehicleList);
}

Further, I tried deleting the sqlite file. Then the vehicleList is fetched properly if I do the fetch for the first time as soon as everything is saved to the sqlite file(which is created afresh now) . Next time I do the fetch, the "vehicleList" is empty.

Please look into the issue.

DanielBroad commented 8 years ago

Hi Sandeep. Can you upload a sample project to github showing the problem please.

sandeepjoshiaw commented 8 years ago

Hi I having some issues with my GitHub repo. So, I have it in my Dropbox, this is the link https://dl.dropboxusercontent.com/s/z5vbgb9piti96uo/TestDB.zip?dl=0&preview=TestDB.zip Let me know if any other information is required.

DanielBroad commented 8 years ago

Thanks for the example project, I believe this issue is now resolved in Master