public function scopes()
{
return array(
'completed'=>array(
'join'=>'INNER JOIN jobs_role j1 ON j1.job_id = '.$this->tableAlias.'.id',
'group' => $this->tableAlias.'.id',
),
'drafted'=>array(
'condition'=>$this->tableAlias.'.id NOT IN (SELECT jobjoin.id from jobs_job jobjoin INNER JOIN jobs_role rolejoin ON jobjoin.author_id = :ypl0 AND rolejoin.job_id = jobjoin.id)',
'group' => $this->tableAlias.'.id',
),
);
}
I mean, could I use the ":ypl0" finder param directly in my subquery? The code works like a charm but… I think is not very orthodox. What others ways exists in yii to use this value in the subquery.
It is really strange I know. But this scope is only used to defined a relation in another model, so in need this :ypl0 (the id used in Where clause). Can I do in other way?
It’s generally better to use $this->getTableAlias() so that you can pass in true/false values for its parameters. Depending on when you use your scopes, you can get ini finite loops if you aren’t careful
Yes, they’re the same if you don’t specify parameters. I guess I was remembering the defaultScope aspect of this for looping issues, here’s where the problem first came up: