From 716b22457b9a2473357e8b1d2e6c17304ba22d87 Mon Sep 17 00:00:00 2001 From: Sergei Winitzki Date: Thu, 16 Aug 2012 16:30:27 +0200 Subject: [PATCH 1/2] implement correctly generated fetch requests with repeating variables. --- mogenerator.m | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/mogenerator.m b/mogenerator.m index 8c651826..e4d066e3 100644 --- a/mogenerator.m +++ b/mogenerator.m @@ -179,6 +179,18 @@ - (NSString *)_resolveKeyPathType:(NSString *)keyPath { return [entity managedObjectClassName]; } +// changes by Sergei Winitzki +// auxiliary function +- (BOOL) bindingsArray:(NSArray *)bindings containsVariableNamed:(NSString *)name { + for (NSDictionary *dict in bindings) { + if ([[dict objectForKey:@"name"] isEqual:name]) { + return YES; + } + } + return NO; +} +// end of changes by Sergei Winitzki + - (void)_processPredicate:(NSPredicate*)predicate_ bindings:(NSMutableArray*)bindings_ { if (!predicate_) return; @@ -209,11 +221,13 @@ - (void)_processPredicate:(NSPredicate*)predicate_ bindings:(NSMutableArray*)bin type = [self _resolveKeyPathType:[lhs keyPath]]; } type = [type stringByAppendingString:@"*"]; - - [bindings_ addObject:[NSDictionary dictionaryWithObjectsAndKeys: + // changes by Sergei Winitzki: 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]]; + } // end of changes by Sergei Winitzki } break; default: assert(0 && "unknown NSExpression type"); From 12bd8c03839a0f52f3874865ca71edf5e41e194e Mon Sep 17 00:00:00 2001 From: Sergei Winitzki Date: Fri, 17 Aug 2012 09:42:56 +0200 Subject: [PATCH 2/2] removed superfluous comments. --- mogenerator.m | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mogenerator.m b/mogenerator.m index e4d066e3..f2739bc6 100644 --- a/mogenerator.m +++ b/mogenerator.m @@ -179,7 +179,6 @@ - (NSString *)_resolveKeyPathType:(NSString *)keyPath { return [entity managedObjectClassName]; } -// changes by Sergei Winitzki // auxiliary function - (BOOL) bindingsArray:(NSArray *)bindings containsVariableNamed:(NSString *)name { for (NSDictionary *dict in bindings) { @@ -189,7 +188,6 @@ - (BOOL) bindingsArray:(NSArray *)bindings containsVariableNamed:(NSString *)nam } return NO; } -// end of changes by Sergei Winitzki - (void)_processPredicate:(NSPredicate*)predicate_ bindings:(NSMutableArray*)bindings_ { if (!predicate_) return; @@ -221,13 +219,13 @@ - (void)_processPredicate:(NSPredicate*)predicate_ bindings:(NSMutableArray*)bin type = [self _resolveKeyPathType:[lhs keyPath]]; } type = [type stringByAppendingString:@"*"]; - // changes by Sergei Winitzki: make sure that no repeated variables are entered here. + // 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]]; - } // end of changes by Sergei Winitzki + } } break; default: assert(0 && "unknown NSExpression type");