Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Core data 谓词子查询以显示关系中至少有1个公共对象的实体_Core Data_Many To Many_Data Modeling_Predicate_Nsfetchrequest - Fatal编程技术网

Core data 谓词子查询以显示关系中至少有1个公共对象的实体

Core data 谓词子查询以显示关系中至少有1个公共对象的实体,core-data,many-to-many,data-modeling,predicate,nsfetchrequest,Core Data,Many To Many,Data Modeling,Predicate,Nsfetchrequest,在我使用的数据模型的一部分中- Department <-->> Person <<-->> Project 我试图获取一个包含所有项目的数组,然后列出departmentA中所有项目匹配的人员。这可能吗?这是正确的方向吗 您是否已经有Entity3实例的列表,这些实例可能与您的条件相匹配?或者您希望在一个谓词中完成所有这些?在数据库中,我有Entity3的列表,该列表与关联的Entity2的列表。我将更新我的问题以澄清。 NSFetchRequest

在我使用的数据模型的一部分中-

Department <-->> Person <<-->> Project

我试图获取一个包含所有项目的数组,然后列出departmentA中所有项目匹配的人员。这可能吗?这是正确的方向吗

您是否已经有Entity3实例的列表,这些实例可能与您的条件相匹配?或者您希望在一个谓词中完成所有这些?在数据库中,我有Entity3的列表,该列表与关联的Entity2的列表。我将更新我的问题以澄清。
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription
                entityForName:@"Project" inManagedObjectContext:_managedObjectContext];
    [fetchRequest setEntity:entity];

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"projectToPerson.personToDepartment = %@", departmentB];

    [fetchRequest setPredicate:predicate];
    NSError *error = nil;
    NSArray *projects = [_managedObjectContext executeFetchRequest:fetchRequest error:&error];

    NSFetchRequest *fetchRequest2 = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity2 = [NSEntityDescription
                                   entityForName:@"Person" inManagedObjectContext:_managedObjectContext];
    [fetchRequest2 setEntity:entity2];
    NSPredicate *predicate2 = [NSPredicate predicateWithFormat:@"personToDepartment = %@ AND SUBQUERY(personToProject, $x, $x.projectName = %@).@count >0", departmentA,projects];

    [fetchRequest2 setPredicate:predicate2];