我有两张桌子。一个是companydetail
,第二个是favCompany
两个都有一个共同的companyID
。如何在companydetail
中插入companyID
的所有favCompany
?这是我的代码:
-(NSArray *)getAll_FavCompany
{
NSMutableDictionary * userinfo = [[NSUserDefaults standardUserDefaults]objectForKey:@"user_info"];
NSManagedObjectContext *managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[managedObjectContext setParentContext:[TDODataManager sharedManager].managedObjectContext];
NSManagedObjectContext *mainManagedObjectContext = [managedObjectContext parentContext];
NSFetchRequest *fetch_company = [NSFetchRequest fetchRequestWithEntityName:@"Tbl_companyFav"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"companyid = %@ AND loginuserid = %@", [userinfo objectForKey:@"user_id"]];
[fetch_company setPredicate:predicate];
NSError *error = nil;
NSArray *result = [mainManagedObjectContext executeFetchRequest:fetch_company error:&error];
return result;
}
我想我需要在上面的代码中使用relationshipKeyPathsForPrefetching
,但我不确定。
答案 0 :(得分:0)