My database structure is like this: Each book is listed in the table Books. Each book has many authors which are listed in the Authors table with a bookId. Each author has many children which are listed in the Children table with an AuthorId.
The relations are defined in the Yii models.
I want to find all Books with a blue cover. Of each book with a blue cover I want to fetch all the author’s children with blonde hair.
I tried this:
$books = Book::model()->with(array(
'authors.children'=>array(
'joinType'=>'LEFT JOIN',
'condition'=>'children.hairColor="blonde"'
)
)
)->findAll();
But because of the condition, only books with authors with blonde children are listed. I want to list all books.