Skip to content

Commit

Permalink
Update mogenerator to handle LHS keyPaths for relationships in predic…
Browse files Browse the repository at this point in the history
…ates
  • Loading branch information
jon authored and rentzsch committed Oct 14, 2009
1 parent 946faaf commit 6bd8051
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions mogenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ - (NSDictionary*)fetchRequestTemplates {
}
return result;
}

- (NSString *)_resolveKeyPathType:(NSString *)keyPath {
NSArray *components = [keyPath componentsSeparatedByString:@"."];

// Hope the set of keys in the key path consists of solely relationships. Abort otherwise

NSEntityDescription *entity = self;
for (NSString *key in components) {
NSRelationshipDescription *relationship = [[entity relationshipsByName] objectForKey:key];
assert(relationship);
entity = [relationship destinationEntity];
}

return [entity managedObjectClassName];
}

- (void)_processPredicate:(NSPredicate*)predicate_ bindings:(NSMutableArray*)bindings_ {
if (!predicate_) return;

Expand Down Expand Up @@ -95,10 +111,7 @@ - (void)_processPredicate:(NSPredicate*)predicate_ bindings:(NSMutableArray*)bin
if (attribute) {
type = [attribute objectAttributeType];
} else {
// Probably a relationship
NSRelationshipDescription *relationship = [[self relationshipsByName] objectForKey:[lhs keyPath]];
assert(relationship);
type = [[relationship destinationEntity] managedObjectClassName];
type = [self _resolveKeyPathType:[lhs keyPath]];
}
type = [type stringByAppendingString:@"*"];

Expand Down

0 comments on commit 6bd8051

Please sign in to comment.