Gangani Roshan
Gangani Roshan

Reputation: 583

to-many key not allowed here

Here, try to fetch record from my two entity name is: Resgistration & Unique. and relationship name is roshan between them. When m execute it display the error : 'NSInvalidArgumentException', reason: 'to-many key not allowed here'

NSManagedObjectContext *context = [appDelegate manageObjectContext];
    NSError *error = nil;

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"roshan.number == %@", @"1"];
    NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Resgistration" inManagedObjectContext:context];

    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    [request setEntity:entityDescription];
    [request setPredicate:predicate];
    [request setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@"Unique",nil]];
    [request setIncludesSubentities:YES];

    NSArray* returnArray = [context executeFetchRequest:request error:&error];
    if([returnArray count] > 0) {

        Resgistration* reg = [returnArray objectAtIndex:0];
        NSLog(@"%@ %@", reg.name, reg.number);
    }

Upvotes: 1

Views: 1144

Answers (1)

Jon Rose
Jon Rose

Reputation: 8563

roshan is a to-many relationship so the statement "roshan.number == 1" is ambiguous.

  • Do you mean that it has at least one roshan with a number equal to 1 ("ANY roshan.number == 1".
  • Do you mean that all of the roshans equal one ("ALL roshan.number == 1").
  • Do you mean that there is one and only one roshan and it has a number of one ("ALL roshan.number == 1 AND roshan.@count == 1").

Upvotes: 3

Related Questions