Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keypath not found when sorting with multiple keys with magical record

When i try to use the MR_findAllSortedBy function with multiple keys, i get a keypath not found error. However, when i use this function with only one of the two keypaths it works. I can't figure why it doesn't work.

My code

-(void)performActionOnEachTrajetWithBlock:(void (^) (Trajet *trajet, NSArray *previousTrajets))actionBlock{

    NSMutableArray *previousTrajets = [NSMutableArray arrayWithArray:@[]];
    for (Trajet *trajet in [Trajet MR_findAllSortedBy:@"isActive, date" ascending:YES]){
        actionBlock(trajet, [NSArray arrayWithArray:previousTrajets]);
        [previousTrajets addObject:trajet];
    }
    return;
}

The error

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath  date not found in entity <NSSQLEntity Trajet id=2>'

Thank you for helping me.

like image 649
Hugo Avatar asked Jan 10 '23 18:01

Hugo


1 Answers

There must be no space in the first argument of

[Trajet MR_findAllSortedBy:@"isActive, date" ascending:YES]
     // remove this space ------------^

otherwise MagicalRecord will create a sort descriptor for the key " date" instead of "date".

like image 123
Martin R Avatar answered Jan 19 '23 23:01

Martin R