From 8369f7108e3eb3d73e10583fe3f4248c914583c7 Mon Sep 17 00:00:00 2001 From: Anthony Mittaz Date: Fri, 23 Jul 2010 21:40:16 +0800 Subject: [PATCH] added hasBindings on prettyFetchRequests --- mogenerator.m | 1 + templates/machine.m.motemplate | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/mogenerator.m b/mogenerator.m index 80ae3d77..2c80e3be 100644 --- a/mogenerator.m +++ b/mogenerator.m @@ -192,6 +192,7 @@ - (NSArray*)prettyFetchRequests { [result addObject:[NSDictionary dictionaryWithObjectsAndKeys: fetchRequestName, @"name", bindings, @"bindings", + [NSNumber numberWithBool:[bindings count] > 0], @"hasBindings", [NSNumber numberWithBool:[fetchRequestName hasPrefix:@"one"]], @"singleResult", nil]]; } diff --git a/templates/machine.m.motemplate b/templates/machine.m.motemplate index 8f8a7480..239e4526 100644 --- a/templates/machine.m.motemplate +++ b/templates/machine.m.motemplate @@ -86,11 +86,15 @@ NSError *error = nil; NSManagedObjectModel *model = [[moc_ persistentStoreCoordinator] managedObjectModel]; + <$if FetchRequest.hasBindings$> NSDictionary *substitutionVariables = [NSDictionary dictionaryWithObjectsAndKeys: <$foreach Binding FetchRequest.bindings do2$> <$Binding.name$>_, @"<$Binding.name$>", <$endforeach do2$> nil]; + <$else$> + NSDictionary *substitutionVariables = nil; + <$endif$> NSFetchRequest *fetchRequest = [model fetchRequestFromTemplateWithName:@"<$FetchRequest.name$>" substitutionVariables:substitutionVariables]; NSAssert(fetchRequest, @"Can't find fetch request named \"<$FetchRequest.name$>\"."); @@ -135,13 +139,17 @@ NSError *error = nil; NSManagedObjectModel *model = [[moc_ persistentStoreCoordinator] managedObjectModel]; - NSFetchRequest *fetchRequest = [model fetchRequestFromTemplateWithName:@"<$FetchRequest.name$>" - substitutionVariables:[NSDictionary dictionaryWithObjectsAndKeys: + <$if FetchRequest.hasBindings$> + NSDictionary *substitutionVariables = [NSDictionary dictionaryWithObjectsAndKeys: <$foreach Binding FetchRequest.bindings do2$> <$Binding.name$>_, @"<$Binding.name$>", <$endforeach do2$> - nil] - ]; + nil]; + <$else$> + NSDictionary *substitutionVariables = nil; + <$endif$> + NSFetchRequest *fetchRequest = [model fetchRequestFromTemplateWithName:@"<$FetchRequest.name$>" + substitutionVariables:substitutionVariables]; NSAssert(fetchRequest, @"Can't find fetch request named \"<$FetchRequest.name$>\"."); NSArray *result = [moc_ executeFetchRequest:fetchRequest error:&error];