0
votes

I have an iPad app, built with XCode 4.5, Storyboard, Core Data (using MagicalRecord) and iOS 6. I have two Entities, each with multiple attributes. The first entity has a one to many relationship with the second entity.

In the MagicalRecord docs, I don't see how to persist the data to the second entity; I read somewhere that Core Data generates it's own key and indexes. I know from past use of SQLite that I would need to set the key from the first entity to be able to access the second entity.

[UPDATED] Here is the modified code but it doesn't work either. I have previously selected a row in didSelectRowAtIndexedPath in another class. I assume that set the localContext. Any ideas why this is not working?

- (IBAction)saveAppointment:(UIButton *)sender {

    AppointmentInfo *newAppointment = [AppointmentInfo MR_createInContext:localContext];  //  create the entity

    newAppointment.aStartTime = selectedStartDate;
    newAppointment.aEndTime= selectedEndDate;

    [localContext MR_saveNestedContexts];
}
2

2 Answers

0
votes

You need to create your Entity in the proper (ie. localContext) context:

[AppointmentInfo MR_createInContext:localContext];
0
votes

I found the problem... seems that I had the store setup incorrectly... I removed the parent pointer from AppointmentInfo and added the "class" information. Works like a champ now... thank you for your time, tho'.