Note that there are some explanatory texts on larger screens.

plurals
  1. POImporting multi-Relational Data with magicalpanda's MagicalRecord
    text
    copied!<p>I would like to import a json-file into my SQLite-CoreData-Database with the help of magical panda's MagicalRecord. This is the Content of my json-file: </p> <pre><code>{ "title":"Gebratener Schweinebauch auf dänische Art", "subtitle":"Stegt flaesk med persillesauce", "preparation_time":"35 Min.", "preparation_subtitle":"bei 225°C, nicht vorheizen.", "components":[ { "name":"Hauptgericht", "ingredients": [ { "name":"1 kg geschälte und gekochte Kartoffeln" } ] } ] } </code></pre> <p>i am trying to import the content of the file into the following core-data-model: Image of the Data model: <a href="http://twitpic.com/8fa0y9" rel="nofollow">http://twitpic.com/8fa0y9</a></p> <p>i use the following code to import the json-file: </p> <pre><code>- (void)initializeRecipeDatabase { NSString *resource = [[NSBundle mainBundle] pathForResource:kRecipeInitialDatabaseContentFilename ofType:kRecipeInitialDatabaseContentFileType]; NSError *parsingError = nil; NSDictionary *result = nil; if (NSClassFromString(@"NSJSONSerialization")) { NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath:resource]; [inputStream open]; result = [NSJSONSerialization JSONObjectWithStream:inputStream options:0 error:&amp;parsingError]; } else { NSData *jsonData = [NSData dataWithContentsOfFile:resource]; result = [jsonData objectFromJSONData]; } [Recipe MR_truncateAll]; [[NSManagedObjectContext MR_defaultContext] MR_save]; [Recipe MR_importFromDictionary:result]; [[NSManagedObjectContext MR_defaultContext] MR_save]; } </code></pre> <p>The import works without giving me an error, but when i inspect the content of the SQLite-Database, i have two equal entries in the Ingredient-Table:</p> <p>Image of the Database-Content: <a href="http://twitpic.com/8fa0k3" rel="nofollow">http://twitpic.com/8fa0k3</a></p> <p>Currently i am kind of helpless, to solve this problem, and i would be very happy, if someone could help me out.</p>
 

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