title: Realm on Swift - Creating Relationship
body: <p>I have two classes that form a one to many relationship:</p>
  
  <pre><code>class FooA: Object {
      dynamic var someAValue: String
  
      let fooBList = List&lt;FooB&gt;()
  }
  
  class FooB: Object {
      dynamic var someBValue: String
  }
  </code></pre>
  
  <p>I add the object into Realm in this fashion:</p>
  
  <pre><code>let fooA = FooA()
  
  fooA.someAValue = 'a value'
  
  let fooB = FooB()
  
  fooB.someBValue = 'a value'
  
  fooA.fooBList.append(fooB)
  
  let realm = try! Realm()
  
  try! realm.write {
     realm.add(fooA)
  }
  </code></pre>
  
  <p>Everything goes well, the object is inserted into Realm.  However, when I attempt to access the FooB object like this:</p>
  
  <pre><code>fooA.fooBList[0]
  </code></pre>
  
  <p>It goes BOOM and the app crashes!  So, obviously, I did not insert the relationship object into Realm correctly and the relationship is corrupted.  What did I miss in the Realm documentation? Must I create the Array first and add it to the parent object in another fashion?</p>
  
  <p>To update on my question, this is the operation that wants to blow up:</p>
  
  <pre><code>FooApiClient.getFooAObjects()
          .subscribeOn(ConcurrentDispatchQueueScheduler(qos: .default))
          .observeOn(MainScheduler.instance)
          .subscribe { [weak self] in
              switch $0 {
              case .next(let fooAObjects):
                  self?.fooAObjects = fooAObjects
              case .completed:
  
                  self?.fooTableView.reloadData()
  
                  loadingView?.hide()
  
              case .error(let error):
                  loadingView?.hide()
  
                  self?.handleError(error)
  
                  self?.showNoFooView()
              }
          }
          .addDisposableTo(disposeBag)
  </code></pre>
  
  <p>The invocation: self?.fooTableView.reloadData() causes to the table view to attempt to display the foo objects retrieved and where it goes BOOM.</p>