如何在谓词中引用子实体名称以获取父实体的提取请求? [英] How can you reference child entity name in a predicate for a fetch request of the parent entity?

查看:84
本文介绍了如何在谓词中引用子实体名称以获取父实体的提取请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have the need to create a complex predicate for an abstract base object. I want to have separate predicate queries for different inheriting entities and key off the sub-entity type, the example below is what I would like to do, however, I have not been able to find a way to reference the entity name or type in the predicate.

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]];


推荐答案

http://bugreport.apple.com =nofollow noreferrer> http://bugreport.apple.com 问题编号7318897:

I got a response from Apple at http://bugreport.apple.com problem number 7318897:


entity.name不是建模的属性,因此它不合法。它工作在二进制存储上的意外。获取子实体的正确方法是在NSFetchRequest上这样做,并使用setIncludesSubentities或不使用。

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.

具有单独的提取请求,并在执行后合并结果集。

So it seems the proper solution is to have separate fetch requests and to merge the result sets after execution.

这篇关于如何在谓词中引用子实体名称以获取父实体的提取请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆