title: Yii2: Filter query by pivot table when using `joinWith()`
body: <p>Take the following sample <code>Cart</code> model. It has a <code>CartItem</code> &quot;pivot record/table&quot; which links it to <code>Item</code>.</p>
  <pre class="lang-php prettyprint-override"><code>class Cart extends ActiveRecord {
  
      public function getCartItems() {
          return $this
              -&gt;hasMany(CartItem::class, ['cart_id' =&gt; 'id'])
              -&gt;inverseOf('cart');
      }
  
      public function getItems($callback = null) {
          return $this
              -&gt;hasMany(Item::class, ['item_id' =&gt; 'id'])
              -&gt;via('cartItems', $callback);
      }
  
  }
  </code></pre>
  <p>(Example #1) At this point I would be able to filter either by <code>Item</code>'s activequery or <code>CartItem</code>'s query like so:</p>
  <pre class="lang-php prettyprint-override"><code>$booksAddedToCartSinceYesterday = $cart
      -&gt;getItems(function($cartItemQuery) {
          $cartItemQuery-&gt;andWhere('cartItem.created_at &gt; NOW()');
      })
      -&gt;andWhere(['item.category' =&gt; 'books']);
  </code></pre>
  <p>(Example #2) But how do I accomplish the same when I use the static <code>find()</code> method in combination with <code>joinWith()</code>? In the following example I am only able to filet by <code>Item</code>'s ActiveQuery, but I no longer have any reference to the <code>CartItem</code>'s ActiveQuery object:</p>
  <pre class="lang-php prettyprint-override"><code>$booksAddedToCartSinceYesterday = Cart::find()
      -&gt;andWhere(['cart.user_id' =&gt; $some_user_id])
      -&gt;joinWith([
          'items' =&gt; function($itemQuery) {
              $itemQuery-&gt;andWhere(['item.category' =&gt; 'books']);
          },
      ]);
  </code></pre>
  <p>How do I modify the code above so that I am able to filter <code>CartItem</code> junction table records like I did in my example #1? How do I access the junction ActiveQuery object so that I can call <code>$cartItemQuery-&gt;andWhere('cartItem.created_at &gt; NOW()');</code>?</p>