title: How to query a complex nested objects in Room?
body: <p>I have several entities that you can see below, the problem is how to select nested lists properly when you have more than one level of nesting. If you take a look at Google repository on <a href="https://github.com/googlesamples/android-architecture-components/tree/master/BasicRxJavaSample" rel="noreferrer">github</a>, you can find very simple example, but not something complex. As documentation says <a href="https://developer.android.com/training/data-storage/room/referencing-data.html#understand-no-object-references" rel="noreferrer">here</a>, Room doesn't allow object references. How to get <code>ResultObject</code> (and how it should look) including all nested lists?</p>
  
  <p>ResultObject should have this info:</p>
  
  <ol>
  <li><code>List&lt;Dialog&gt;</code></li>
  <li><code>Dialog</code> entity has <code>List&lt;Message&gt;</code>.  </li>
  <li><code>Message</code> has <code>List&lt;ImageContent&gt;</code>.</li>
  <li><code>ImageContent</code> has <code>List&lt;ImageContentItem&gt;</code></li>
  </ol>
  
  <p>Dialog</p>
  
  <pre><code>@Entity(tableName = "dialog")
  data class Dialog(@PrimaryKey val id String, val title: String)
  </code></pre>
  
  <p>Message</p>
  
  <pre><code>@Entity(tableName = "message",
          foreignKeys = [(ForeignKey(entity = Dialog::class, parentColumns ["id"], childColumns = ["dialogId"]))])
  data class Message(@PrimaryKey val id: String, val dialogId: String)
  </code></pre>
  
  <p>ImageContent</p>
  
  <pre><code>@Entity(tableName = "image_content",
          foreignKeys = [(ForeignKey(entity = Message::class, parentColumns = ["id"], childColumns = ["messageId"]))])
  data class ImageContent(@PrimaryKey val id: String, val messageId: String)
  </code></pre>
  
  <p>ImageContentItem</p>
  
  <pre><code>@Entity(tableName = "image_content_item",
          foreignKeys = [(ForeignKey(entity = ImageContent::class, parentColumns = ["id"], childColumns = ["imageContentId"]))])
  data class ImageContentItem(val imageContentId: String,
                          @PrimaryKey(autoGenerate = true) val id: Long = 1)
  </code></pre>
  
  <p>DAO:</p>
  
  <pre><code>@Dao
  interface DialogDao {
      @Query("SELECT * FROM dialog " +
              "INNER JOIN message ON message.dialogId = dialog.id " +
              "INNER JOIN image_content ON image_content.messageId = message.id " +
              "INNER JOIN image_content_item ON image_content_item.imageContentId = image_content.id")
      fun getDialogAllInformation(): Flowable&lt;List&lt;**ResultObject**&gt;&gt;
  }
  </code></pre>