title: Firestore DocumentReference type to object
body: <p>As you can see in the picture, the documents in the person collection refer to the statistics collection.
  <a href="https://i.stack.imgur.com/gd6Wb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gd6Wb.png" alt="Firestore collections" /></a></p>
  <p>I can pull this data like this</p>
  <p>PersonRepository</p>
  <pre><code>override fun getPersonsFromFirestore(): Flow&lt;Response&lt;List&lt;Person&gt;&gt;&gt; = callbackFlow {
      val snapshotListener =
          personsCollection.addSnapshotListener { snapshot, e -&gt;
              val response = if (snapshot != null) {
  
                  val personList = snapshot.toObjects(Person::class.java)
                  Response.Success(personList)
  
              } else {
                  throw Error(e?.message ?: e.toString())
              }
              trySend(response).isSuccess
          }
      awaitClose {
          snapshotListener.remove()
      }
  }
  </code></pre>
  <p>Model</p>
  <pre><code>data class Person(
      val id: Int=0,
      val name: String=&quot;&quot;,
      val surname: String=&quot;&quot;,
      val image_url: String=&quot;&quot;,
      val biography: String=&quot;&quot;,
      val team: String=&quot;&quot;,
      val statistics: DocumentReference? = null,
      var personStatistics: PersonStatistics? = null
  )
  </code></pre>
  <p>How can I convert Document Reference to object here?</p>
  <p>I tried this first</p>
  <pre><code> override fun getPersonsFromFirestore(): Flow&lt;Response&lt;List&lt;Person&gt;&gt;&gt; = callbackFlow {
      val snapshotListener =
          personsCollection.addSnapshotListener { snapshot, e -&gt;
              val response = if (snapshot != null) {
                  val personList = mutableStateListOf&lt;Person&gt;()
  
                  snapshot.onEach {
                      val person = it.toObject(Person::class.java)
  
                          person.statistics!!.get().addOnSuccessListener {
                              val personStatistics = it.toObject(PersonStatistics::class.java)
                              person.personStatistics = personStatistics
                          }
  
                      personList.add(person)
                  }
                  //val personList = snapshot.toObjects(Person::class.java)
                  Response.Success(personList)
              } else {
                  throw Error(e?.message ?: e.toString())
              }
  
              trySend(response).isSuccess
          }
      awaitClose {
          snapshotListener.remove()
      }
  }
  </code></pre>
  <p>but in this approach Person Statistics comes first as null. It is added later. How can I bring them all at once? Or is there another better way?</p>