title: Android Realm Query Relationship
body: <p>I have a Realm Object called TodoList which has a property of RealmList like this.</p>
  
  <pre><code>   @PrimaryKey
      private int id;
      private String title;    
      private RealmList&lt;Task&gt; tasks;
  </code></pre>
  
  <p>And I here the Task Realm object </p>
  
  <pre><code>   @PrimaryKey
      private int id;
      private String title; 
      private boolean completed;
      private TodoList todoList;
  </code></pre>
  
  <p>My question what is the best way to write a Realm query that returns that list of Tasks that belong to a particular TodoList. Here is my approach.</p>
  
  <pre><code>public RealmResults&lt;Task&gt; getTodoListTasks(int todoListId) {
          RealmResults&lt;Task&gt; tasks = mRealm.where(Task.class)
                  .equalTo("todoList.id", todoListId).findAll();
          return tasks;
  }
  </code></pre>
  
  <p>This approach requires that I query the Task table looking for all the TodoList foreign keys that matches a given id. I was hopping for something like this:</p>
  
  <pre><code> public RealmResults&lt;Task&gt; getTodoListTasks2(TodoList list) {
          TodoList todoList =  mRealm.where(TodoList.class).equalTo("id", list.getId()).findFirst();
          RealmResults&lt;Task&gt; tasks = todoList.getTasks();
          return tasks;
  
      }
  </code></pre>
  
  <p>However this will not build because I cannot cast RealmList to RealmResult. </p>