I want to use a parametrised scope within a normal scope but can’t get it working
For example:
If I have this scope called "isEligibleForStats":
/**
* @return array scopes
*/
public function scopes()
{
return array(
'isEligibleForStats'=>array(
'condition'=>"transmission_started_at > '".date('Y-m-d H:i:s',strtotime('-10 days'))."'",
'scopes'=>array('ofStatus'=>array('Sent'))
),
);
}
Where the "ofStatus" named parameterized scope is:
public function ofStatus($status)
{
$criteria = new CDbCriteria;
$criteria->compare('status', $status);
$this->getDbCriteria()->mergeWith($criteria);
return $this;
}
and I do
Blah::model()->isEligibleForStats()->findAll();
The SQL produced by Yii is
SELECT * FROM `blah` `t` WHERE transmission_started_at > '2013-06-03 09:53:31'
The SQL doesn’t have the where clause I wanted from the “ofStatus” scope (AND status = ‘Sent’).
Have I got the wrong syntax or is it just not possible to use a parameterised scope within a normal scope?
I did try some different syntaxes, without luck:
'scopes'=>array('ofStatus','Sent')
'scopes'=>array('ofStatus'=>'Sent')
'scopes'=>array('ofStatus'=>array('Sent'))
'scopes'=>array("ofStatus('Sent')")