问题:
为简单起见,我有两个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/