title: How can I have an optional one-to-one relationship in GORM?
body: <p>I have 2 objects, <code>ObjectA</code> and <code>ObjectB</code>.</p>
  
  <p>When <code>ObjectA</code> gets created, <code>ObjectB</code> doesn't (and <em>can't</em>, due to not having the data yet) exist yet.</p>
  
  <p>Once <code>ObjectB</code> is created, it needs to have a corresponding <code>ObjectA</code> attached to it <em>if an appropriate one exists</em>. If there isn't an appropriate <code>ObjectA</code>, then the new <code>ObjectB</code> simply isn't connected to one.</p>
  
  <p>So, all <code>ObjectA</code> instances will <em>eventually</em> be attached to an <code>ObjectB</code>, but not all <code>ObjectB</code> instances will have an <code>ObjectA</code>.</p>
  
  <p>Essentially, I'm looking for GORM to build database tables like this:</p>
  
  <pre><code>ObjectA
  - Id (NotNull, unique)
  - ObjectB_Id[FK: ObjectB.Id] (unique)
  
  ObjectB
  - Id (NotNull, unique)
  </code></pre>
  
  <p><strong>How can I put together the GORM domain classes to do this?</strong></p>
  
  <p>I've tried just about every combination of <code>hasOne</code>, <code>belongsTo</code>, raw properties, <code>nullable: true</code> and <code>unique: true</code> constraints I can think of, but I <em>must</em> be missing one. This doesn't seem like it's a particularly <em>odd</em> scenario, so there <em>must</em> be some way to accomplish this.</p>