Note that there are some explanatory texts on larger screens.

plurals
  1. POView contents of core data in emulator
    primarykey
    data
    text
    <p>I have a one-to-many CoreData model. There are tasklists and tasks belonging to the tasklists. My problem is that whenever I create a new task, a tasklist is also created. </p> <p><img src="https://i.stack.imgur.com/IDawF.png" alt=""></p> <p>"new tasklist" is the default value of the name field in the db. "New tasklist" is the value stored by the View when it creates a new tasklsit. As can be seen, every time a task is created, a tasklist with the default name value is automatically created.</p> <p><strong>Question</strong> Is this how it is supposed to look? If so, how do I do a query to pick only the tasklist names where Z_ENT = 1 (those are the parents, right?) If this looks very wrong, how do I insert stuff correctly. I think my table relationships are correct - but if that might be the problem, I ll post screenshots.</p> <p><strong>Model Diagram</strong> <img src="https://i.stack.imgur.com/0kcva.png" alt="enter image description here"></p> <p><strong>My Code</strong></p> <p>When a list is selected:</p> <pre><code> NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath]; TaskViewController *taskViewController = [[TaskViewController alloc] init]; taskViewController.managedObjectContext = [self.fetchedResultsController managedObjectContext]; taskViewController.tasklist = managedObject; </code></pre> <p>In the TaskViewController, I get the fetchedResultsController like this:</p> <pre><code> NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(tasklistOfTask == %@)", tasklist]; [fetchRequest setPredicate: predicate]; NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"]; aFetchedResultsController.delegate = self; self.fetchedResultsController = aFetchedResultsController; </code></pre> <p>and then to insert,</p> <pre><code> NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext]; NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity]; NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context]; [newManagedObject setValue:@"dummy" forKey:@"task"]; [newManagedObject setValue:tasklist forKey:@"tasklistOfTask"]; </code></pre> <p>the managedobjectcontext is passed in from AppDelegate.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload