importFromObject: creates garbage object if the relatedObject could not be found #521

Closed
CraigSiemens opened this Issue Jul 15, 2013 · 1 comment

Projects

None yet

2 participants

@CraigSiemens
Contributor

I'll try and explain the issue using Cars and Images as defined below.
screen shot 2013-07-15 at 11 20 08 am

{
  "carID": 1,
  "name": "Car 1",
  "images": [
    {
      "imageID": 1,
      "name": "Image 2"
    },
    {
      "imageID": 2,
      "name": "Image 2"
    }
  ]
}

When I import a Car with the above data, it works fine. The Car is created, the Images are created and the relationships are set.

{
  "carID": 1,
  "name": "Car 1",
  "images": [
    1,
    2
  ]
}

However, when I import a Car with this data, there are 2 things that can happen:

  1. If the Images already exist in core data everything works fine
  2. If the Images have not been imported yet, it creates new Image objects and sets the relationship.

The problem with case 2 is that when it creates the Images, it doesn't set any properties on the Image, not even the ID. So now the Car has a relationship with garbage Images with no properties set on them.

As far as I can tell, it's because its expecting a NSDictionary of values instead of a NSNumber. If I edit MR_importValuesForKeysWithObject: to use the following code, it appears fix the issue and not break any of the other cases that were working. However, since I'm relatively new to MagicalRecord, I dont know if there are any other cases that I may not know about.

if ([localObjectData isKindOfClass:[NSNumber class]]) {
    [relatedObject setValue:localObjectData forKey:[relationshipInfo MR_primaryKey]];
}
else {
    [relatedObject MR_importValuesForKeysWithObject:localObjectData];
}
Contributor

Given the age of this issue, and the volume of issues we have to work through, I've decided to close this alongside a number of other older issues.

If you can still replicate the issue under the latest in-development version of MagicalRecord (3.0 at the time of writing), please feel free to re-open and one of @magicalpanda/team-magicalrecord will take another look. Thanks!

@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