title: Android Room: Handling Relations with LiveData
body: <p>So I have two models(tables), <code>WordGroups</code> and <code>Words</code>, and the relation between them is one to many.
  So my models and <code>Dao</code> look like:</p>
  
  <pre><code>@Entity
  public class WordGroup {
  
      @PrimaryKey
      private int id;
  
      @Ignore
      private List&lt;Word&gt; words;
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public List&lt;Word&gt; getWords() {
          return words;
      }
  
      public void setWords(List&lt;Word&gt; words) {
          this.words = words;
      }
  }
  
  @Entity
  public class Word {
  
      @PrimaryKey
      private int id;
  
      @ForeignKey(entity = WordGroup.class, parentColumns = "id", childColumns = "wordGroupId")
      private int wordGroupId;
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public int getWordGroupId() {
          return wordGroupId;
      }
  
      public void setWordGroupId(int wordGroupId) {
          this.wordGroupId = wordGroupId;
      }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>@Dao
  public interface Dao {
  
      @Query("select * from WordGroup where id = :id")
      LiveData&lt;WordGroup&gt; selectWordGroupById(int id);
  
      @Query("select * from WordGroup")
      LiveData&lt;List&lt;WordGroup&gt;&gt; selectAllWordGroups();
  
      @Query("select * from Word where wordGroupId = :wordGroupId")
      LiveData&lt;List&lt;Word&gt;&gt; selectWordsByWordGroupId(int wordGroupId);
  }
  </code></pre>
  
  <p>now I have a method that selects a <code>WordGroup</code> and also sets its <code>Word</code>s using <code>Transformations</code>:</p>
  
  <pre><code>public LiveData&lt;WordGroup&gt; getWordGroupWithWords(int id) {
      LiveData&lt;WordGroup&gt; wordGroupLiveData = dao.selectWordGroupById(id);
  
      LiveData&lt;WordGroup&gt; wordGroupWithWordsLiveData = Transformations.switchMap(wordGroupLiveData, inputWordGroup -&gt; {
          LiveData&lt;List&lt;Word&gt;&gt; wordsLiveData = dao.selectWordsByWordGroupId(inputWordGroup.getId());
  
          LiveData&lt;WordGroup&gt; outputWordGroupsLiveData = Transformations.map(wordsLiveData, inputWords -&gt; {
              inputWordGroup.setWords(inputWords);
              return inputWordGroup;
          });
  
          return outputWordGroupsLiveData;
      });
  
      return wordGroupWithWordsLiveData;
  }
  </code></pre>
  
  <p>now I want to write a method that selects all the <code>WordGroup</code>s that also sets their <code>Word</code>s for each <code>WordGroup</code>. the signature of the method should be something like:</p>
  
  <pre><code>public LiveData&lt;List&lt;WordGroup&gt;&gt; getAllWordGroupsWithWords();
  </code></pre>