Yii Framework Forum: Relations, Scopes, Subqueries And Finder Params - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Relations, Scopes, Subqueries And Finder Params Rate Topic: -----

#1 User is offline   Jose H. Milán 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 21-July 11
  • Location:España

Posted 15 March 2013 - 06:33 AM

Is possible to do that?

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?

Thank you
0

#2 User is offline   acorncom 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 100
  • Joined: 25-February 11
  • Location:CO, USA

Posted 19 March 2013 - 12:47 AM

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 :-)
0

#3 User is offline   Jose H. Milán 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 21-July 11
  • Location:España

Posted 20 March 2013 - 02:52 PM

View Postfr0d0z, on 19 March 2013 - 12:47 AM, said:

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


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?

Thanks
0

#4 User is offline   acorncom 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 100
  • Joined: 25-February 11
  • Location:CO, USA

Posted 21 March 2013 - 04:50 PM

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:

http://www.yiiframew...ularly-crashes/

So, sorry and never mind :-)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users