title: Why is Yii2's ActiveRecord using lots of single SELECTs instead of JOINs?
body: <p>I'm using Yii2's ActiveRecord implementation in (hopefully) exactly the way it should be used, according to the docs. </p>
  
  <h2>Problem</h2>
  
  <p>In a quite simple setup with simple relations betweens the tables, fetching 10 results is fast, 100 is slow. 1000 is impossible. The database is extremely small and indexed perfectly. The problem is definitly Yii2's way to request data, not the db itself.</p>
  
  <p>I'm using a standard ActiveDataProvider like:</p>
  
  <pre><code>$provider = new ActiveDataProvider([
      'query' =&gt; Post::find(),
      'pagination' =&gt; false // to get all records
  ]);
  </code></pre>
  
  <h2>What I suspect</h2>
  
  <p>Debugging with the Yii2 toolbar showed thousands of single SELECTs for a simple request that should just get 50 rows from table A with some simple "JOINs" to table B to table C. In plain SQL everybody would solve this with one SQL statement and two joins. Yii2 however fires a SELECT for every relation in every row (which makes sense to keep the ORM clean). Resulting in (more or less) 1 * 50 * 30 = 1500 queries for just getting two relations of each row.</p>
  
  <h2>Question</h2>
  
  <p>Why is Yii2 using so many single SELECTs, or is this a mistake on my side ?
  Addionally, does anybody know how to "fix" this ?</p>
  
  <p><em>As this is a very important issue for me I'll provide 500 bounty on May 14th.</em></p>