开发者

Query regarding fetchrequest for coreData

开发者 https://www.devze.com 2023-02-24 22:54 出处:网络
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).
  • 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 In开发者_JAVA百科voice 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消