Note that there are some explanatory texts on larger screens.

plurals
  1. POMagical record 1 to many relationships objective c
    primarykey
    data
    text
    <p>I'm using <a href="https://github.com/magicalpanda/MagicalRecord" rel="nofollow">Magical Record</a> for database with Xcode. I have two entities, one is named 'task' and the other is 'comment', I want to make a relationship so that one task has an array of comments when I query for a task, is it possible, I am new with magical record, hope I made the problem understandable. Thanks.</p> <p>edit: hey, thanks for your help, i used this code to put the comments in a task:</p> <pre><code>NSManagedObjectContext *localContext = [NSManagedObjectContext MR_defaultContext]; TarefaMR *task = [TarefaMR MR_createInContext:localContext]; task. //... for (NSDictionary *comment in [tarefa objectForKey:@"comments"]) { NSManagedObjectContext *localContext3 = [NSManagedObjectContext MR_defaultContext]; ComentarioMR *comment = [ComentarioMR MR_createInContext:localContext3]; [localContext3 MR_saveToPersistentStoreAndWait]; [task addComentariosObject:comment]; } [localContext MR_saveToPersistentStoreAndWait]; </code></pre> <p>but now i try to access it and i cant seem to get the data from the comments from a task,</p> <p>code I used :</p> <pre><code>for (TarefaMR *tarefa in [TarefaMR MR_findAll];) { NSLog(@"tarefa.comentarios %@",tarefa.comentarios); } </code></pre> <p>I get a </p> <blockquote> <p>tarefa.comentarios Relationship 'comentarios' fault on managed object : comentarios = ;</p> </blockquote> <p>I already tried to loop tarefa.comentarios in a for, but dont seem to get anything, if i query the comments database, the objects are there.</p> <p>Then for I tried to use:</p> <pre><code>for (ComentarioMR *comment in tarefa.comentarios) { NSLog(@"comment listHeader %@", comment.listHeader); NSLog(@"comment listText %@", comment.listText); } </code></pre> <p>how can i get the comments of the task? </p>
    singulars
    1. This table or related slice is empty.
    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.
    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