• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Predicates with object identity values
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Predicates with object identity values


  • Subject: Re: Predicates with object identity values
  • From: Chris Hanson <email@hidden>
  • Date: Fri, 25 May 2007 00:39:01 -0700

On May 24, 2007, at 5:41 PM, Glen Low wrote:

In Core Data, specifically predicate programming, is it possible to create a NSPredicate to search on an object identity value (as opposed to a string, number or bool value)?

Yes, see below.

A Department object has many Employee objects. There is a relation Department -> Employee (employee) but no inverse relation Employee - > Department.

Generally speaking, all relationships should have an inverse. Otherwise Core Data has to guess as to the intent of the relationship in some situations, and it may guess differently than you would.


What is it you hope to gain by not having an inverse relationship?

Suppose I have an Employee object called myEmployee and want to search for its Department, can I use the following fetch request?

NSFetchRequest* request = [[NSFetchRequest alloc] init];
[request setEntity: departmentEntity];
[request setPredicate: [NSPredicate predicateWithFormat: @"employee = %@", myEmployee]]; // using myEmployee as an object identity

This is exactly how you'd do it. You could also have passed myEmployee's managed object ID instead; which can be useful in some situations (e.g. multithreading).


  -- Chris


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Predicates with object identity values
      • From: Glen Low <email@hidden>
References: 
 >Predicates with object identity values (From: Glen Low <email@hidden>)

  • Prev by Date: NSImage question
  • Next by Date: NSColor + Bindings
  • Previous by thread: Predicates with object identity values
  • Next by thread: Re: Predicates with object identity values
  • Index(es):
    • Date
    • Thread