Relations, Scopes, Subqueries And Finder Params

Is possible to do that?

public function scopes()


  return array(


	'join'=>'INNER JOIN jobs_role j1 ON j1.job_id = '.$this->tableAlias.'.id',

	'group' => $this->tableAlias.'.id',



      'condition'=>$this->tableAlias.'.id NOT IN (SELECT from jobs_job jobjoin INNER JOIN jobs_role rolejoin ON jobjoin.author_id = :ypl0 AND  rolejoin.job_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?

Thank you

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 :slight_smile:

Confused about that.

Is not the same to use $this->getTableAlias() and $this->tableAlias ? I guess it is totally the same if you don’t need to specify any param…

About infinite loops in this case… I don’t understand you, could you please give me and example?


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:

So, sorry and never mind :slight_smile: