Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing Data using MagicalRecord

I'm using MagicalRecord to import data from plist. I'm using code less import as explained in this tutorial Importing Data Made Easy.

I have two entities Manufacturer and Car, they have one to many and one to one relation respectively.

Core Data Model

Plist structure

enter image description here

This import work fine

NSArray *manufacturers = ...

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
        [manufacturers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            [Manufacturer MR_importFromObject:obj inContext:localContext];
        }];
    } completion:^(BOOL success, NSError *error) {

}];

But this is not getting imported

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
        [Manufacturer MR_importFromArray:manufacturers inContext:localContext];
    } completion:^(BOOL success, NSError *error) {

}];

Any explanation would be highly appreciated.

EDIT : Log of manufacturers array

[
    {
        "Cars": [
            {
                "CarID": 1,
                "Name": "Civic"
            },
            {
                "CarID": 2,
                "Name": "Jazz"
            },
            {
                "CarID": 3,
                "Name": "City"
            }
        ],
        "ManufacturerID": 1,
        "Name": "Honda"
    }
]
like image 287
Anupdas Avatar asked Nov 02 '22 23:11

Anupdas


1 Answers

The issue seems to be like a bug in MagicalRecord, found an open bug filed for this issue.

MR_importFromArray: was using MR_saveWithBlock: replacing with saveWithBlockAndWait: solves the issue. Bug Fix

like image 79
Anupdas Avatar answered Nov 15 '22 07:11

Anupdas