Changeset 325

Show
Ignore:
Timestamp:
09/01/08 08:57:34 (4 months ago)
Author:
wolf
Message:

[NEW] mogenerator 1.12: Handle relationships in the left-hand side of fetch request predicate expressions.
[FIX] failure when handling fetch requests without a filtering predicate.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cocoa/mogenerator/mogenerator.m

    r319 r325  
    7070} 
    7171- (void)_processPredicate:(NSPredicate*)predicate_ bindings:(NSMutableArray*)bindings_ { 
     72    if (!predicate_) return; 
     73     
    7274        if ([predicate_ isKindOfClass:[NSCompoundPredicate class]]) { 
    7375                nsenumerate([(NSCompoundPredicate*)predicate_ subpredicates], NSPredicate, subpredicate) { 
     
    9395                if (attribute) { 
    9496                    type = [attribute objectAttributeType]; 
    95                     type = [type stringByAppendingString:@"*"]; 
    9697                } else { 
    9798                    //  Probably a relationship 
    98                     assert(0&&"TODO: add relationship support"); 
     99                    NSRelationshipDescription *relationship = [[self relationshipsByName] objectForKey:[lhs keyPath]]; 
     100                    assert(relationship); 
     101                    type = [[relationship destinationEntity] managedObjectClassName]; 
    99102                } 
     103                type = [type stringByAppendingString:@"*"]; 
    100104                 
    101105                                [bindings_ addObject:[NSDictionary dictionaryWithObjectsAndKeys: 
     
    329333    if (_version) 
    330334    { 
    331         printf("mogenerator 1.11. By Jonathan 'Wolf' Rentzsch + friends.\n"); 
     335        printf("mogenerator 1.12. By Jonathan 'Wolf' Rentzsch + friends.\n"); 
    332336        return EXIT_SUCCESS; 
    333337    } 
  • trunk/cocoa/mogenerator/mogeneratorTestMule/MOs/_ChildMO.h

    r317 r325  
    3636 
    3737 
     38 
     39+ (NSArray*)fetchByParent:(NSManagedObjectContext*)moc_ parent:(ParentMO*)parent_; 
     40+ (NSArray*)fetchByParent:(NSManagedObjectContext*)moc_ parent:(ParentMO*)parent_ error:(NSError**)error_; 
     41 
     42 
    3843@end 
  • trunk/cocoa/mogenerator/mogeneratorTestMule/MOs/_ChildMO.m

    r317 r325  
    5757 
    5858 
     59 
     60+ (NSArray*)fetchByParent:(NSManagedObjectContext*)moc_ parent:(ParentMO*)parent_ { 
     61        NSError *error = nil; 
     62        NSArray *result = [self fetchByParent:moc_ parent:parent_ error:&error]; 
     63        if (error) { 
     64                [NSApp presentError:error]; 
     65        } 
     66        return result; 
     67} 
     68+ (NSArray*)fetchByParent:(NSManagedObjectContext*)moc_ parent:(ParentMO*)parent_ error:(NSError**)error_ { 
     69        NSError *error = nil; 
     70         
     71        NSManagedObjectModel *model = [[moc_ persistentStoreCoordinator] managedObjectModel]; 
     72        NSFetchRequest *fetchRequest = [model fetchRequestFromTemplateWithName:@"byParent" 
     73                                                                                                         substitutionVariables:[NSDictionary dictionaryWithObjectsAndKeys: 
     74                                                                                                                 
     75                                                                                                                parent_, @"parent", 
     76                                                                                                                 
     77                                                                                                                nil] 
     78                                                                                                         ]; 
     79        NSAssert(fetchRequest, @"Can't find fetch request named \"byParent\"."); 
     80         
     81        NSArray *result = [moc_ executeFetchRequest:fetchRequest error:&error]; 
     82        if (error_) *error_ = error; 
     83        return result; 
     84} 
     85 
     86 
    5987@end 
  • trunk/cocoa/mogenerator/mogeneratorTestMule/MOs/_HumanMO.h

    r324 r325  
    5858 
    5959 
     60 
     61+ (NSArray*)fetchAllHumans:(NSManagedObjectContext*)moc_ ; 
     62+ (NSArray*)fetchAllHumans:(NSManagedObjectContext*)moc_  error:(NSError**)error_; 
     63 
     64 
    6065@end 
  • trunk/cocoa/mogenerator/mogeneratorTestMule/MOs/_HumanMO.m

    r324 r325  
    151151 
    152152 
     153 
     154+ (NSArray*)fetchAllHumans:(NSManagedObjectContext*)moc_  { 
     155        NSError *error = nil; 
     156        NSArray *result = [self fetchAllHumans:moc_  error:&error]; 
     157        if (error) { 
     158                [NSApp presentError:error]; 
     159        } 
     160        return result; 
     161} 
     162+ (NSArray*)fetchAllHumans:(NSManagedObjectContext*)moc_  error:(NSError**)error_ { 
     163        NSError *error = nil; 
     164         
     165        NSManagedObjectModel *model = [[moc_ persistentStoreCoordinator] managedObjectModel]; 
     166        NSFetchRequest *fetchRequest = [model fetchRequestFromTemplateWithName:@"allHumans" 
     167                                                                                                         substitutionVariables:[NSDictionary dictionaryWithObjectsAndKeys: 
     168                                                                                                                 
     169                                                                                                                nil] 
     170                                                                                                         ]; 
     171        NSAssert(fetchRequest, @"Can't find fetch request named \"allHumans\"."); 
     172         
     173        NSArray *result = [moc_ executeFetchRequest:fetchRequest error:&error]; 
     174        if (error_) *error_ = error; 
     175        return result; 
     176} 
     177 
     178 
    153179@end 
  • trunk/cocoa/mogenerator/mogeneratorTestMule/MOs/include.m

    r319 r325  
     1#include "ChildMO.m" 
     2#include "_ChildMO.m" 
    13#include "ParentMO.m" 
    24#include "_ParentMO.m" 
    35#include "HumanMO.m" 
    46#include "_HumanMO.m" 
    5 #include "ChildMO.m" 
    6 #include "_ChildMO.m"