I am playing with Yii and having some trouble with Yii Eager Loading vs lazy loading database query. For example comparing two ways:
$comment = Comment::model()->with(array('issue'=>array('condition'=>'project_ id='.$projectId)))->findAll();2a.
$comment = Comment::model()->findAll
2b. to get Issue:
$issue = $comment->issues (assume that we have declare "issues" relation in Comment model).
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:
3.
$comment ->issues
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).
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.