ios - 在NSFetchRequest的propertiesToFetch中包括一对一关系中的属性

标签 ios objective-c nsfetchrequest

问题:
为简单起见,我有两个NSManagedObjects(A和B),其中B与A具有一对一的关系。在我的propertiesToFetch中,使用B作为实体类型,我具有许多B属性。这可行,但是我想要的还包括一对一关系中A的属性(例如``名称'')。

有什么建议吗?

编辑:

NSFetchRequest *fetchR = [NSFetchRequest fetchRequestWithEntityName:ClassName(B)];
fetchR.predicate = [NSPredicate predicateWithFormat:@"active = %u",1];
fetchR.resultType = NSDictionaryResultType;
fetchR.propertiesToFetch = [NSArray arrayWithObjects:
                            [self propertyDescriptionFor:@"name" inEntity:ClassName(B)],
                            [self propertyDescriptionFor:@"age" inEntity:ClassName(B)], 
// Here is where I want to add something like "a.name"
                            nil];

最佳答案

我不知道propertyDescriptionFor:inEntity:方法(在哪里定义?),但是您可以在propertiesToFetch中提供一个字符串数组:

fetchR.propertiesToFetch = [NSArray arrayWithObjects:@"name", @"age", @"a.name", nil];

一对一的关系应该“正常”。

关于ios - 在NSFetchRequest的propertiesToFetch中包括一对一关系中的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15586086/

相关文章:

ios - "Ambiguous use of ' 进行 CKQuerySubscription 时 firesOnRecordCreation '"

ios - 客户端凭证流 - 获取访问 token

ios - 如何调试缓慢的应用程序启动

ios - 如何编写具有多个排序描述符的 NSFetchRequest?

ios - 从核心数据 swift 4 中获取关系

ios - 快速获取PHAsset信息?

Objective-C 将字符串添加到 html 包中

ios - 添加抽象父实体时如何迁移核心数据数据模型?

ios - NSFetchedResultsController performFetch 不起作用

ios - NSDate 到 Tick 的转换