Reputation: 2991
as written in Yii documentation we can use Active Record this way
$users=User::model()->with(array(
'posts'=>array(
'select'=>false,
'joinType'=>'INNER JOIN',
'condition'=>'posts.published=1',
),
))->findAll();
I want to make some similar query but with posts of some category if Post HAS_MANY Category
$users=User::model()->with(array(
'posts.categories'=>array(
'select'=>false,
'joinType'=>'INNER JOIN',
//how should I write condition here?
'condition'=>'posts.categories.id=1',
),
))->findAll();
Is it possible and what is the right syntax? I get 'unknown column posts.categories.id here
Upvotes: 0
Views: 651
Reputation: 8587
Use on
instead of condition
. Also the right alias
is rather categories
(depends on how you defined the relation in posts
.
'on' => 'categories.id=1'
Upvotes: 1