title: What is the idiomatic way to implement foreign keys in CouchDB?
body: <p>Let me state a simple example: You have an Order and a Shopping Cart. One way I envision persisting this is to save an Order document and a Cart document. The Order document could have a field called "shopping-cart" whose value is the UUID of the relevant Cart document. Another way I can imagine doing this is to save an Order document with the "shopping-cart" field containing an associative array of the entire Cart. In other words, instead of saving the Cart explicitly as an independent document, I embed the Cart document in the Order document. </p>
  
  <p>What if we decide later that a Cart should be persistent, so a returning user will find his half-finished Cart waiting for him across sessions? I imagine we could then combine both methods, keeping the Cart separate while it's incomplete and embedding it in the Order document when it's finalized/purchased.</p>
  
  <p>Both methods would work, though I worry about CouchDB not having foreign key constraints; in the first method the Cart document could be deleted, leaving you with a corrupt data set.</p>
  
  <p>How do you decide which method to use? Is one of these methods more idiomatic to CouchDB? Are there any methods I missed?</p>
  
  <p>I'm new to CouchDB so it's difficult for me to see the advantages/disadvantages to having a more or less normalized structure.</p>