title: Self-Referencing Data Object in CoreData
body: <p>I'm making the mental switch from a lifetime of SQL to CoreData and it's not without a few hiccups. The thing that's kicking me at the moment is creating a self-referencing object. Allow me to explain.</p>
  <p>Using SQL terminology, I have a table that contains the steps in a process. To keep it simple, I'll say the table holds two pieces of information - the name of the step and the step that comes after it (which may or may not be the next record in the table). All steps in the process are stored in a single table. Each step will ALWAYS have one step that comes after it. But not all steps have a step that comes before it.</p>
  <p>In other words, it should look something like this:</p>
  <p><a href="https://i.stack.imgur.com/6mfBw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6mfBw.png" alt="desired outcome" /></a><br />
  <sub>(source: <a href="http://justinwhitney.com/images/desiredOutcome.png" rel="nofollow noreferrer">justinwhitney.com</a>)</sub></p>
  <p>In the SQL world, I would make a single table with an identity field, the name, and a foreign key referencing its own identity field (I guess that would be a domestic key?), thusly:</p>
  <p><a href="https://i.stack.imgur.com/wqgYz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wqgYz.png" alt="SQL version" /></a><br />
  <sub>(source: <a href="http://justinwhitney.com/images/usingSQL.png" rel="nofollow noreferrer">justinwhitney.com</a>)</sub></p>
  <p>However, with relationships, there is no such thing as an identity field. Nor is there a select query I can create to pull the info I need.</p>
  <p>So what is the best approach for creating an Entity that does the same thing? I tried creating a relationship that inverted to itself and that turned out to be a hard to debug disaster. What are the other options?</p>
  <p>Thank you!</p>