Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct generation of fetch requests with repeated variables #125

Merged
merged 2 commits into from
Aug 17, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions mogenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ - (NSString *)_resolveKeyPathType:(NSString *)keyPath {
return [entity managedObjectClassName];
}

// auxiliary function
- (BOOL) bindingsArray:(NSArray *)bindings containsVariableNamed:(NSString *)name {
for (NSDictionary *dict in bindings) {
if ([[dict objectForKey:@"name"] isEqual:name]) {
return YES;
}
}
return NO;
}

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

Expand Down Expand Up @@ -209,11 +219,13 @@ - (void)_processPredicate:(NSPredicate*)predicate_ bindings:(NSMutableArray*)bin
type = [self _resolveKeyPathType:[lhs keyPath]];
}
type = [type stringByAppendingString:@"*"];

[bindings_ addObject:[NSDictionary dictionaryWithObjectsAndKeys:
// make sure that no repeated variables are entered here.
if (![self bindingsArray:bindings_ containsVariableNamed:[rhs variable]]) {
[bindings_ addObject:[NSDictionary dictionaryWithObjectsAndKeys:
[rhs variable], @"name",
type, @"type",
nil]];
}
} break;
default:
assert(0 && "unknown NSExpression type");
Expand Down