title: Mapping MongoDB documents to case class with types but without embedded documents
body: <p><a href="https://github.com/osinka/subset" rel="nofollow">Subset</a> looks like an interesting, thin MongoDB wrapper.</p>
  
  <p>In one of the examples given, there are Tweets and Users. However, <code>User</code> is a <em>subdocument</em> of <code>Tweet</code>. In  classical SQL, this would be normalized into two separate tables with a foreign key from Tweet to User. In MongoDB, this wouldn't necessitate a <code>DBRef</code>, storing the user's <code>ObjectId</code> would be sufficient.</p>
  
  <p>Both in Subset and Salat this would result in these case classes:</p>
  
  <pre><code>case class Tweet(_id: ObjectId, content: String, userId: ObjectId)
  case class User(_id: ObjectId, name: String)
  </code></pre>
  
  <p>So there's no guarantee that the ObjectId in Tweet actually resolves to a User (making it less typesafe). I also have to write the same query for each class that references User (or move it to some trait).</p>
  
  <p>So what I'd like to achieve is to have <code>case class Tweet(_id: ObjectId, content: String, userId: User)</code>, in code, and the <code>ObjectId</code> in the database. Is this possible, and if so, how? What are good alternatives?</p>