Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Pull Request: Fixed KVC relationship mapping bug #247

Merged
merged 1 commit into from

4 participants

@JRG-Developer

Please pull this into master.

I spent hours trying to debug my own code before I realized that this bug existed in Magical Import.

There was only one line changed (see code diff), but it's pretty significant.

Thanks.

@blackgold9
Collaborator

Can you explain what this change does. Not familiar with this part of the code base. Also, adding a unit test that verifies this behavior would be great. Thanks!

@blackgold9
Collaborator

Do you have a code sample that triggered the bug and explain how this change fixes it? Don't want to roadblock you on a unit test, but I need to understand it before it get's committed.

@JRG-Developer

Here's my stack overflow post on it:
http://stackoverflow.com/questions/12312888/magical-records-how-to-map-relationships-using-key-path

I will create a unit test for this too.

@blackgold9
Collaborator

Any progress on the unit test? I'd like to merge this.

@cmezak

crap. I just made a pull request for this. I'll see if I can come up with a unit test for my request.

@cmezak

…but in the meantime, @blackgold9, if you have a look at the KVC documentation, I think you'll be convinced that it's safe to merge this request. @JRG-Developer merely replaces valueForKey: with valueForKeyPath:. The latter simply splits the key by occurrences of '.' and calls valueForKey: recursively for each component.

Since KVC doesn't allow '.' as part of a key, in any case where valueForKey: returns a value, valueForKeyPath: should return the same value. @JRG-Developer's request simply makes this code more flexible – as it was intended to be.

@casademora
Owner
@cmezak

I had a separate pull request with the same change that I just closed. This one is still open and ready to be merged in when somebody pulls the trigger,

@blackgold9 blackgold9 merged commit 272af9c into magicalpanda:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 7, 2012
  1. @JRG-Developer
This page is out of date. Refresh to see the latest.
View
2  MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalDataImport.m
@@ -126,7 +126,7 @@ - (void) MR_setRelationships:(NSDictionary *)relationships forKeysWithDictionary
NSRelationshipDescription *relationshipInfo = [relationships valueForKey:relationshipName];
NSString *lookupKey = [[relationshipInfo userInfo] valueForKey:kMagicalRecordImportRelationshipMapKey] ?: relationshipName;
- id relatedObjectData = [relationshipData valueForKey:lookupKey];
+ id relatedObjectData = [relationshipData valueForKeyPath:lookupKey];
if (relatedObjectData == nil || [relatedObjectData isEqual:[NSNull null]])
{
Something went wrong with that request. Please try again.