gpt4 book ai didi

iphone - 如何在父实体的获取请求的谓词中引用子实体名称?

转载 作者:行者123 更新时间:2023-12-03 18:38:10 26 4
gpt4 key购买 nike

我需要为抽象基础对象创建一个复杂的谓词。我想对不同的继承实体进行单独的谓词查询并关闭子实体类型,下面的示例是我想要做的,但是,我无法找到引用实体名称或类型的方法谓词。

NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = [NSEntityDescription entityForName:@"MyCommonObjectBase" inManagedObjectContext:myContext];

NSPredicate *subclassAPredicate = [NSPredicate predicateWithFormat:@"someValue > %@ && entityName = %@", 100, @"SubclassA"];
NSPredicate *subclassBPredicate = [NSPredicate predicateWithFormat:@"someValue < %@ && entityName = %@", 50, @"SubclassB"];

request.predicate = [NSCompoundPredicate orPredicateWithSubpredicates:[NSArray arrayWithObjects:subclassAPredicate, subclassBPredicate, nil]];

最佳答案

我收到了 Apple 的回复:http://bugreport.apple.com问题号7318897:

entity.name is not a modeled property, so it's not legal. it works by accident on the binary store. The correct way to fetch subentities is to do so on the NSFetchRequest and use either setIncludesSubentities or not.

所以看来正确的解决方案是有单独的获取请求并在执行后合并结果集。

关于iphone - 如何在父实体的获取请求的谓词中引用子实体名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1579337/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com