I have two tables Content and Post. They connected with each other by ‘contentId’ key.
I have model User and I would like to count user’s content (‘userId’ key in Content). But I also need to check if Post.type=1 for each user’s content.
I added ‘contentCount’ relation to relations():
function relations()
{
return array(
'contentCount'=>array(self::STAT, 'Content', 'userId',
'condition'=>'t.status=1 AND Post.type=1',
'join'=>'Post ON Post.contentId=t.contentId',
),
);
}
It creates such SQL:
SELECT `userId` AS `c`, COUNT(*) AS `s` FROM
`Content` WHERE (status=1 AND Post.type=1)
AND (`Content`.`userId`=1) GROUP BY `userId`)
Of course I get such error: Unknown column ‘Post.type’ in ‘where clause’.
Why there are no JOIN condition in SQL statement?
How should I use ‘join’ option in relations.
My Yii v.1.1.4.