Skip to content

Commit

Permalink
added hasBindings on prettyFetchRequests
Browse files Browse the repository at this point in the history
  • Loading branch information
sync authored and rentzsch committed Jul 26, 2010
1 parent f711fc5 commit 8369f71
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions mogenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
}
Expand Down
16 changes: 12 additions & 4 deletions templates/machine.m.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -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$>\".");
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 8369f71

Please sign in to comment.