title: Yii Eager Loading vs Lazy loading
body: <p>I am playing with Yii and having some trouble with Yii <strong>Eager Loading</strong> vs <strong>lazy loading</strong> database query. For example comparing two ways: </p>
  
  <ol>
  <li><p><code>$comment = Comment::model()-&gt;with(array('issue'=&gt;array('condition'=&gt;'project_
  id='.$projectId)))-&gt;findAll();</code></p></li>
  <li><p>2a. <code>$comment = Comment::model()-&gt;findAll</code></p></li>
  </ol>
  
  <p>2b. to get Issue: </p>
  
  <p><code>$issue = $comment-&gt;issues</code> (assume that we have declare "issues" relation in Comment model).</p>
  
  <p>I am not sure what advantages of the first approach. As I understand the 1st code will return only Comment BUT also run the get Issue query (like 2b code). However, as I see (thouth not sure there is better way to take advantage of "Eager Loading") if I want to get Issues of Comment in 1st code, I also have to run this code: </p>
  
  <p>3.</p>
  
  <pre><code>$comment -&gt;issues
  </code></pre>
  
  <p>If so, as I guest, we have to run 2 queries with the Eager loading approach, so it takes long time than "Lazy loading", because it run the "get Issue query" two times (fist time when we run the 1st code, and second time we run the 3rd code).</p>
  
  <p>So, could you verify my though, or if it wrong could you tell me how to get all Issues from the Eager Loading approach that take advantage of its efficiency.</p>