Permalink
Browse files

added hasBindings on prettyFetchRequests

  • Loading branch information...
1 parent f711fc5 commit 8369f7108e3eb3d73e10583fe3f4248c914583c7 @sync sync committed with Jul 23, 2010
Showing with 13 additions and 4 deletions.
  1. +1 −0 mogenerator.m
  2. +12 −4 templates/machine.m.motemplate
View
1 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]];
}
View
16 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];

0 comments on commit 8369f71

Please sign in to comment.