title: Yii2 models - active record joinWith + andWhere date selection
body: <p>I like to select specific related data on two related Yii2 <code>models</code>. Both models stuck in a <code>1:n</code> relation. The relation is working fine!</p>
  
  <hr>
  
  <p><strong>Order</strong> model:</p>
  
  <ul>
  <li>@property integer $id</li>
  </ul>
  
  <p>Order model relation define: </p>
  
  <pre><code>/**
   * @return \yii\db\ActiveQuery
   */
  public function getTimeCaptures()
  {
      return $this-&gt;hasMany(TimeCapture::className(), ['orderId' =&gt; 'id']);
  }
  </code></pre>
  
  <p><strong>timeCapture</strong> model: </p>
  
  <ul>
  <li>@property integer $id</li>
  <li>@property integer $orderId</li>
  <li>@property string $date (its <code>Datetime</code> in MySQL-DB)</li>
  </ul>
  
  <hr>
  
  <p>I like to get all <code>orders</code> with related <code>timeCaptures</code> between a specific date. The following statement will give me all <code>timeCaptures</code>. It seems like the <code>andWhere</code> clauses are not working!</p>
  
  <pre><code>/**
   * Build query
   */
  $orders = Order::find()
      -&gt;joinWith('timeCaptures')
      -&gt;andWhere([
          '&gt;=',
          'timeCapture.date',
          $startDateSearch-&gt;format('Y-m-d H:i:s')
      ])
      -&gt;andWhere([
          '&lt;=',
          'timeCapture.date',
          $endDateSearch-&gt;format('Y-m-d H:i:s')
      ])-&gt;all();
  </code></pre>
  
  <p>This is raw SQL output of <code>$orders-&gt;createCommand()-&gt;getRawSql()</code>:</p>
  
  <pre><code>SELECT `order`.*
      FROM `order`
  LEFT JOIN `timeCapture` ON `order`.`id` = `timeCapture`.`orderId`
      WHERE (`timeCapture`.`date` &gt;= '2017-02-01 00:00:00')
      AND (`timeCapture`.`date` &lt;= '2017-02-28 00:00:00')
  </code></pre>
  
  <p>Please provide a answer which uses <a href="http://www.yiiframework.com/doc-2.0/yii-db-activerecord.html" rel="nofollow noreferrer">Yii2 active records</a>. Thanks in advance.</p>