0

In Yii framework, how can I disable defaultScope ?

I tried with resetScope(false) and resetScope(true) but to no avail.

Any help would be really appreciated.

GAMITG
  • 3,810
  • 7
  • 32
  • 51
user1244197
  • 61
  • 2
  • 13
  • if you can't avoid using that function, just set some scope after it – Developerium Dec 04 '14 at 05:56
  • Hi @tinybyte I tried that as well but somehow the default scope is always getting added. – user1244197 Dec 04 '14 at 06:09
  • @tinybyte public function defaultScope() { $t = $this->getTableAlias(false, false); return ['condition' => "`$t`.`status`= 1" ]; } public function scopes() { $t = $this->getTableAlias(false, false); return [ 'displayOff' => ['condition' => "`$t`.`status` = 2 "], ];    } I am using it like. XXX::model()->resetScope(true)->displayOff(); but the QUERY fired is select * from XXX Where XXX.status = 1 and XXX.status = 2; – user1244197 Dec 04 '14 at 06:13
  • which version of yii are you using http://www.yiiframework.com/doc/api/1.1/CActiveRecord#resetScope-detail from documentation it is available since 1.1.2. Please update your question with your yii version. – gvgvgvijayan Dec 04 '14 at 06:57
  • thank you for your comment.. I checked the Yii version and apparently its 1.1.15 which is lower than 1.1.2.. But I am just curious.. I checked the sourcode for resetScope function for 1.1.2 (mentioned in docs) and 1.1.15 which I had.. and it seems same .. so my question is where is the change ???? and why is it not working?? – user1244197 Dec 04 '14 at 07:11
  • It would help if you added the code for your model and your call to `resetScope` in the question. Look at [the page for MVCE](http://www.yiiframework.com/doc/api/1.1/CDbCommand#query-detail) for more information – topher Dec 04 '14 at 07:26

1 Answers1

0

you can disable defaultScode by overriding defaultScope() method and returning empty array.

public function defaultScope()
{
    return array();
}
turutosiya
  • 1,051
  • 10
  • 17