1
votes
  • 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?

1
This worked for me: [NSPredicate predicateWithFormat:@"client == %@ AND ( invoice IN %@ OR invoice == nil)" I was trying [NSNull null] instead of nil earlier and that did not work.siasl

1 Answers

2
votes

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