importFromObject crashes with bad_access #214

Closed
danielwischer opened this Issue Jul 19, 2012 · 9 comments

Comments

Projects
None yet
6 participants
@danielwischer

Hi folks,

i really like magical record and used it in several projects.
Now i am building a facebook-app and one part is to load all friends from facebok and save it to coredata.

So i wanted to use magicalimport to import an array of friends.

But magicalrecord crashes in NSManagedObject+MagicalRecord.m in line 33. All attributes are named like the key in the dictionary, except the id attribute, which i defined in the userinfo section.

Any ideas on what to check? I read about setting the primarykeyattribute, but i dont have any relationships. Just one entity with 4 attributes.

Ask for further info if you need.

Regards,
Daniel

@itavero

This comment has been minimized.

Show comment Hide comment
@itavero

itavero Oct 12, 2012

I'm having the same issue with iOS 6. Have you been able to fix it?

itavero commented Oct 12, 2012

I'm having the same issue with iOS 6. Have you been able to fix it?

@melbic

This comment has been minimized.

Show comment Hide comment
@melbic

melbic Jun 25, 2013

Contributor

Same here.

Contributor

melbic commented Jun 25, 2013

Same here.

@BarryBatser

This comment has been minimized.

Show comment Hide comment
@BarryBatser

BarryBatser Jun 25, 2013

I have the same problem when mapping 4 attributes via UserInfo dictionary and using this sample:

// TEST
[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {

    // Test data
    NSDictionary* data = @{@"id": @"1",
                           @"email": @"test@email.nl",
                           @"name": @"Barry",
                           @"gender": @"male"};

    User* test = [User importFromObject:data];
    NSLog(@"Test: %@", test);
}];

Edit:

When changing the code in NSManagedObject+MagicalDataImport.m from line 239 to this code, it works:

//    NSManagedObject *managedObject = [self MR_findFirstByAttribute:[primaryAttribute name] withValue:value inContext:context];
//    if (managedObject == nil) 
//    {
//        managedObject = [self MR_createInContext:context];
//    }

// TEST
NSManagedObject *managedObject = [self MR_createInContext:context];

I have the same problem when mapping 4 attributes via UserInfo dictionary and using this sample:

// TEST
[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {

    // Test data
    NSDictionary* data = @{@"id": @"1",
                           @"email": @"test@email.nl",
                           @"name": @"Barry",
                           @"gender": @"male"};

    User* test = [User importFromObject:data];
    NSLog(@"Test: %@", test);
}];

Edit:

When changing the code in NSManagedObject+MagicalDataImport.m from line 239 to this code, it works:

//    NSManagedObject *managedObject = [self MR_findFirstByAttribute:[primaryAttribute name] withValue:value inContext:context];
//    if (managedObject == nil) 
//    {
//        managedObject = [self MR_createInContext:context];
//    }

// TEST
NSManagedObject *managedObject = [self MR_createInContext:context];
@BarryBatser

This comment has been minimized.

Show comment Hide comment
@BarryBatser

BarryBatser Jun 25, 2013

Found out what was the problem by debugging in MagicalRecord. It seems if you forget to set a "primary" key with the relatedByAttribute key in the user info dictionary it will crash.

Found out what was the problem by debugging in MagicalRecord. It seems if you forget to set a "primary" key with the relatedByAttribute key in the user info dictionary it will crash.

@melbic

This comment has been minimized.

Show comment Hide comment
@melbic

melbic Jun 25, 2013

Contributor

So you'll just set one of the attributes (even if there are no relations) as "primary"?

Contributor

melbic commented Jun 25, 2013

So you'll just set one of the attributes (even if there are no relations) as "primary"?

@ryanjm

This comment has been minimized.

Show comment Hide comment
@ryanjm

ryanjm Aug 15, 2013

Contributor

@BarryBatser Can you help me out by expanding on your comment a little bit. The documentation around this is pretty thin.

How do I identify the "primary key"?

I have two models, User and Account and both use myID as the primary key. The User model has an accountID attribute on it. It is a one to many relationship (Account has many users). So what information do I need to put in "User Info" for:

  • User's myID attribute
  • Account's myID attribute
  • User's account relationship
  • Account's users relationship

Any help would be greatly appreciated! Thanks.

Contributor

ryanjm commented Aug 15, 2013

@BarryBatser Can you help me out by expanding on your comment a little bit. The documentation around this is pretty thin.

How do I identify the "primary key"?

I have two models, User and Account and both use myID as the primary key. The User model has an accountID attribute on it. It is a one to many relationship (Account has many users). So what information do I need to put in "User Info" for:

  • User's myID attribute
  • Account's myID attribute
  • User's account relationship
  • Account's users relationship

Any help would be greatly appreciated! Thanks.

@tonyarnold

This comment has been minimized.

Show comment Hide comment
@tonyarnold

tonyarnold Aug 19, 2013

Contributor

@ryanjm, can you take a look and see if #537 helps? I ran into something that sounds pretty similar a few days ago and submitted that PR.

Contributor

tonyarnold commented Aug 19, 2013

@ryanjm, can you take a look and see if #537 helps? I ran into something that sounds pretty similar a few days ago and submitted that PR.

@ghost ghost assigned tonyarnold Aug 19, 2013

@ryanjm

This comment has been minimized.

Show comment Hide comment
@ryanjm

ryanjm Aug 20, 2013

Contributor

Hey @tonyarnold. Thanks for the follow up. My issues was actually just not understanding how to properly get everything setup. Namely I was leaving out relatedByAttribute on the entity itself (and #447 also helped). I'm currently working through my models and making sure everything imports correctly.

Contributor

ryanjm commented Aug 20, 2013

Hey @tonyarnold. Thanks for the follow up. My issues was actually just not understanding how to properly get everything setup. Namely I was leaving out relatedByAttribute on the entity itself (and #447 also helped). I'm currently working through my models and making sure everything imports correctly.

@tonyarnold

This comment has been minimized.

Show comment Hide comment
@tonyarnold

tonyarnold Apr 8, 2014

Contributor

There have been fixes for this issue applied to the upcoming 2.3 and 3.0 releases. Thanks for your patience, guys!

Contributor

tonyarnold commented Apr 8, 2014

There have been fixes for this issue applied to the upcoming 2.3 and 3.0 releases. Thanks for your patience, guys!

@tonyarnold tonyarnold closed this Apr 8, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment