I am working with coreData one -to many relationship. For example folder - file. So what I want to do is that take a file from one folder and copy it to another folder.
So for example
folder A B
file a b
file c d
Now I want to copy file c from folder A to folder B and it should look this way
folder A B
file a b
file c d
file c
To perform this operation I have written this code This is happening in some View Controller which opens after some navigation operations
firstly I am extracting all the folders here
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Folder" inManagedObjectContext:self.managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescription];
NSError *error = nil;
m_folderResults = [self.managedObjectContext executeFetchRequest:request error:&error];
then I have created a new instance of file
File *fileObject = [NSEntityDescription insertNewObjectForEntityForName:@"File" inManagedObjectContext:self.managedObjectContext];
fileObject = (passed file object to this ViewController)
Folder *folderObject = [m_folderResults objectAtIndex:m_indexPath.row];
NSMutableOrderedSet *files = [folderObject mutableOrderedSetValueForKey:@"file"];
[files addObject:fileObject];
This is working but the problem I am facing is that I am getting it this way
folder A B
file a b
file d
file c
Meaning it is getting deleted from one folder and getting added to another folder.
So I want to know where I am going wrong.
Regards Ranjit