关于 coreData 的 fetchrequest 的查询

发布于 2024-11-01 22:08:02 字数 470 浏览 0 评论 0原文

  • 我有一个客户端实体,它与条目实体有很多关系(条目)。
  • 客户端实体还与发票实体(发票)具有一对多关系。
  • 发票实体与条目实体(发票)也具有一对多关系。

  • 客户端<--->>>入口

  • 客户端<--->>发票
  • 发票<--->>输入

当我想为客户端 C1 创建新发票或编辑现有发票 INV1 时,我想获取与客户端 C1 关联且尚未与任何发票关联(尚未开具发票)的所有实体的列表,或者已与 INV1 链接。

简单的 SQL 表示是

SELECT * from entries where client= c1 and (invoice IS null or invoice = INV1)

如何在 CoreData 中编写类似的谓词?

  • I have a Client Entity and it has a to many relationship (entries) with Entry entity.
  • Client Entity also has a to many relationship with an Invoice Entity (invoices).
  • Invoice Entity also has a to many relationship with Entry Entity (invoices).

  • Client <--->> Entry

  • Client <--->> Invoice
  • Invoice <--->> Entry

When I want to create a new Invoice or Edit an existing Invoice INV1 for a Client C1, I would like to fetch the list of all Entities which are associated with Client C1 and are not associated with any invoice yet (not invoiced yet) or are already linked with INV1.

A plain SQL representation would be

SELECT * from entries where client= c1 and (invoice IS null or invoice = INV1)

How can I write a similar predicate in CoreData?

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

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

发布评论

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

评论(1

ま柒月 2024-11-08 22:08:02

试试这个。

predicate = [NSPredicate predicateWithFormat:@"(invoice == nil) || (invoice == %@)", invoice];

这是一个很好的页面,可以了解更多信息

http:// developer.apple.com/library/mac/#documentation/cocoa/Conceptual/Predicates/predicates.html

我通常在页面右上角下载 pdf。然后我就可以搜索我要找的东西

Try this out.

predicate = [NSPredicate predicateWithFormat:@"(invoice == nil) || (invoice == %@)", invoice];

here is a nice page to learn more

http://developer.apple.com/library/mac/#documentation/cocoa/Conceptual/Predicates/predicates.html

i normally download the pdf in the top right of the page. then i can search for what i am looking for

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