0

私は3つのエンティティを持っています

Forms{
    name:string
    jobs<-->>JSAjobs.form
}

JSAjobs{
    name:string
    form<<-->Forms.jobs
}

Jobs{
    step:string
    jobs<<-->Forms.jobs
}

このエラーが発生しています:

objectID 0x95afe60 の対多関係障害「ジョブ」。. . データベースから実行されます。0 行を取得しました

次に、最初に Forms エンティティの行を保存します。次に、Form エンティティの最後のレコードを取得する必要があります。次のようなJSAjobs詳細を含む新しい行を作成します。JSAjop

ありがとう

    NSMutableArray *jobData = [[NSMutableArray alloc]initWithArray:controller.jobData];
NSManagedObjectContext *context = [self managedObjectContext];


NSError *error;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"JSAform" inManagedObjectContext:context];
[fetchRequest setEntity:entity];

NSPredicate *testForFalse = [NSPredicate predicateWithFormat:@"emailed == NO"];

[fetchRequest setPredicate:testForFalse];

NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];

NSLog(@"Fetched Rows: %i", [fetchedObjects count]);

//NSManagedObject *existingParent= //... results of a fetch
JSAform *lastForm = [fetchedObjects objectAtIndex:0];

JSAjobs *newJobs = [NSEntityDescription insertNewObjectForEntityForName:@"JSAjobs" inManagedObjectContext:context];
// Setting new values
newJobs.jobType = [NSString stringWithFormat:@"%@", [jobData objectAtIndex:0]];
newJobs.jobName = [NSString stringWithFormat:@"%@", [[[jobData objectAtIndex:1]objectAtIndex:0] objectAtIndex:0]];
newJobs.comments = [NSString stringWithFormat:@"%@", [[[jobData objectAtIndex:1]objectAtIndex:0] objectAtIndex:1]];
newJobs.date = [NSDate date];
[newJobs setValue:lastForm forKey:@"form"];

if (![context save:&error]) {
    NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}

//New SOP Value
JOBsop *jobSOP = [NSEntityDescription insertNewObjectForEntityForName:@"JOBsop" inManagedObjectContext:context];
for (int i = 0; i< [[jobData objectAtIndex:1]count]; i++){
    NSLog(@"Value for key: %i", i);
    if (i > 0){
        for (int k = 0; k< [[[jobData objectAtIndex:1]objectAtIndex:i] count]; k++){

            jobSOP.step = [[[jobData objectAtIndex:1]objectAtIndex:i] objectAtIndex:k];
            [jobSOP setValue:newJobs forKey:@"jobs"];
       // [NSNumber numberWithInt:[txtBoots.text integerValue]];
        NSLog(@"Simple key: %@", [[[jobData objectAtIndex:1]objectAtIndex:i] objectAtIndex:k]);
        }
    }
}
if (![context save:&error]) {
    NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}
enter code here
4

1 に答える 1