CoreData - 如果关系有数据,则 NSPredicate 结果

发布于 2024-12-02 03:42:45 字数 431 浏览 2 评论 0原文

我在表之间存在多对多关系,并使用活动填充 tableView。 为此,我使用一个简单的 NSPredicate,如下所示:

request.predicate = [NSPredicate predicateWithFormat:@"deleted == %@", [NSNumber numberWithBool:NO]];

在此处输入图像描述

我怎样才能只显示具有成员的活动附在它上面?

我认为在 NSPredicate 中我必须进行一些计数,以便只有 count > 的 Activity 才有效。返回 0。是这样吗? 如何?

(我是 coredata 的新手...)

谢谢,

RL

I have a many-to-many relationship between tables, and I populate a tableView with Activities.
For that i user a simple NSPredicate like this:

request.predicate = [NSPredicate predicateWithFormat:@"deleted == %@", [NSNumber numberWithBool:NO]];

enter image description here

How can I do to show only the Activities that has Members attached to it?

I think that in the NSPredicate I have to do some count so that only the Activities with count > 0 are returned. Is that so?
How?

(i'm newbie in coredata...)

Thanks,

RL

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

緦唸λ蓇 2024-12-09 03:42:45

您需要向作用于 CompanyActivity 实体的谓词添加一个子查询,如下所示:

[[NSPredicate predicateWithFormat:@"deleted == %@" && (0 >= SUBQUERY(Members, $sub, $sub.deleted == %@).@count)", [NSNumber numberWithBool:NO] [NSNumber numberWithBool:NO]];

谓词的第一部分返回尚未删除的对象,与子查询相关的第二部分将负责检索其成员已删除的所有 CompanyActivity 对象。没有被删除。

You need to add a subquery to your predicate acting on the CompanyActivity entity as follows:

[[NSPredicate predicateWithFormat:@"deleted == %@" && (0 >= SUBQUERY(Members, $sub, $sub.deleted == %@).@count)", [NSNumber numberWithBool:NO] [NSNumber numberWithBool:NO]];

The first part of the predicate returns objects which have not been deleted, the second one related to the subquery will take care of retrieving all those CompanyActivity objects whose Members have not been deleted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文