Note that there are some explanatory texts on larger screens.

plurals
  1. POMagicalRecord save array with relationship
    primarykey
    data
    text
    <p>I have three tables. Table Run,Pin and Note. Relationship between them are:</p> <p><strong>1 Run N Pin</strong></p> <p><strong>1 Pin N Note</strong></p> <p>I'm trying to update Run, insert one Pin(pointing to Run) and insert N Notes(pointing to Pin). And, when user goes to another screen, I get the notes of the inserted pin. But, my problem is that is returning just one note. So, I don't know if the error is on the Update/Insert method or on find method. I tried a lot of different ways to do that, but any of them solved my problem.</p> <p><em>Insert/Update:</em></p> <pre><code>[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) { // Get current Run Run *runDb = (Run*) [localContext objectWithID:self.idRun]; //Create a pin Pin *newPin = [Pin MR_createInContext:localContext]; [newPin setSt_description:self.txtName.text]; [newPin setRun: runDb]; /* Set latitude &amp; longitude */ newPin.dec_latitude = (NSDecimalNumber *)[NSDecimalNumber numberWithDouble:currentLocation.coordinate.latitude]; newPin.dec_longitude = (NSDecimalNumber *)[NSDecimalNumber numberWithDouble:currentLocation.coordinate.longitude]; /* Update run, incrementing total pins*/ int pins = [runDb.int_total_pin intValue]; NSNumber *pinsN = [NSNumber numberWithInt:pins+1]; [runDb setInt_total_pin:pinsN]; for (int i=0; i&lt;[notes count]; i++) { Note *note = [Note MR_createInContext:localContext]; [note setSt_note:[[notes objectAtIndex:i] st_note]]; [note setPin:newPin]; } } completion:^(BOOL success, NSError *error) { if(!success) NSLog(@"%@", error); }]; </code></pre> <p><em>Find Method (Get all notes of a pin)</em></p> <pre><code>-(NSArray*) getNotesFromPin:(NSManagedObjectID*) pinId{ NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"pin == %@", pinId]; //Return notes from pin return [Note MR_findAllWithPredicate:predicate1]; } </code></pre> <p>On the log, I can see that MagicalRecord is inserting 5 objects (3 notes, 1 pin and 1 run):</p> <pre><code>NSManagedObjectContext(MagicalRecord) MR_contextWillSave:](0xba9ba70) Context BACKGROUND SAVING (ROOT) is about to save. Obtaining permanent IDs for new 5 inserted objects 2013-11-24 19:24:28.103 MyProject[35447:1ea1b] __70-[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:]_block_invoke_021(0xba9ba70) → Finished saving: &lt;NSManagedObjectContext (0xba9ba70): *** BACKGROUND SAVING (ROOT) ***&gt; on *** BACKGROUND THREAD *** </code></pre>
    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.
    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