jeudi 30 avril 2015

How to delete a record from relational table using coredata?

I am new to coredata database. I have created two tables 1. UserTable 2. ActivityTable

I have created a relation ship between two tables UserTable have a relationship with ActivityTable and the inverse of UserTable ActivityTable have a relationship with UserTable and the inverse of ActivityTable I have implemented like this

    NSManagedObjectContext *context = [appDelegate managedObjectContext];
    // Test listing all users from the store
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"UserTable" inManagedObjectContext:context];
    [fetchRequest setEntity:entity];
    NSError *error;
    NSArray *fetchedObjects_Login = [context executeFetchRequest:fetchRequest error:&error];


    if ( fetchedObjects_Login != nil &&  [fetchedObjects_Login count] > 0){
        for(NSManagedObject *managedObject in fetchedObjects_Login){
            [context deleteObject:managedObject];
        }

        if (![context save:&error]) {
            NSLog(@"Error deleting %@ - error:",[error localizedDescription]);
        }
    }

Note: I am unable to delete the record from database. Please let us know how to resolve this. Here, I got the error. I Want's to delete the record from userTable.

Aucun commentaire:

Enregistrer un commentaire