Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, I'm not sure I understand your question, but I'll try and answer in the context of a simple domain model.</p> <p>Let's say you have a <code>Person</code> class and a <code>Computer</code> class, both extend <code>NSManagedObject</code>. <code>Person</code> is linked to <code>Computer</code> via a one-way relationship, a NSSet named <code>computers</code>.</p> <p>This would allow you to say in your code:</p> <pre><code>Person *person = // ... (loaded from database) NSSet *computers = person.computers; for (Computer *computer : computers) { // do something fun } </code></pre> <p>However, since it's a one-way relationship, you would <em>not</em> be able to do this:</p> <pre><code>Computer *computer = // loaded from DB Person *person = computer.person; // This line won't work </code></pre> <p>Therefore, since it won't work -- there's no backwards relationship -- the only way to get the related Person class would be to build a Fetch Request to query the database and find the Person instances that have the Computer as a member.</p> <pre><code>NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSPredicate *predicate = // define your NSPredicate to find the Person object here [fetchRequest setPredicate:predicate]; NSError *error = nil; NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&amp;error]; [fetchRequest release]; </code></pre> <p>Generally speaking, that's <em>annoying</em>. So, it's generally a good idea to define your relationships bi-directionally (e.g. with inverse) if possible, that would enable you to just do:</p> <pre><code>Person *person = computer.person; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload