Anupdas
Anupdas

Reputation: 10201

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"
    }
]

Upvotes: 5

Views: 1992

Answers (1)

Anupdas
Anupdas

Reputation: 10201

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

Upvotes: 2

Related Questions