Hello,
maybe someone has the the same Problem and could help me. I want to define a scope in a model with declared relations. One relation is static.
class User extends CActiveRecord{...
public function relations(){
return array(
...
'videos' => array(self::HAS_MANY, 'Video', 'creator_id'),
'averageRating' => array(self::STAT, 'Video', 'creator_id',
'condition' => 'status_id = 3',
'select' => 'AVG(rating)'),
...
)...
If I create now a scope with the ‘videos’ relation, it works! But if I will create a scope with the static one, this failed. Here my code that works:
'scopeTest' => array( 'select' => 't.id',
'with' => array('videos'=>array('alias' =>'v',
'select' => 'status_id, rating',
'joinType' =>'INNER JOIN')),
'condition' => 'v.status_id = 3 AND v.rating >= 9,
)
This code works, but I couldn’t generate a avarage rating - maybe its not supported. And the other relation didn’t work:
'scopeTest' => array( 'select' => 't.id',
'with' => array('averageRating'=>array('alias' => 'r',
'on' => 't.id = r.creator_id',
'joinType'=>'INNER JOIN')),
'condition' => "r.rating >= 9,
)
My purpose is to create a list with users but purge the users, which have videos whose rating is to small. There are further eliminations, which should handled with scopes. But at first I have to find a solution for this problem.
Thx for all help.
Greetings…