this tip is emerged from this topic with Mikes great idea to put it in a simple behavior.
So, if you have a defaultScope (e.g. for hiding records with a soft deletion) and you want to disable this default scope in some particular cases (e.g. an admin page where soft deleted records could be undeleted) you may add a behavior like the following:
<?php
class DisableDefaultScopeBehavior extends CActiveRecordBehavior
{
private $_defaultScopeDisabled = false; // Flag - whether defaultScope is disabled or not
public function disableDefaultScope()
{
$this->_defaultScopeDisabled = true;
return $this->Owner;
}
public function getDefaultScopeDisabled() {
return $this->_defaultScopeDisabled;
}
}
?>inside your model override the defaultScope() function like this:
public function defaultScope()
{
return $this->getDefaultScopeDisabled() ?
array() :
array(
// Your default scope goes here e.g.
// 'condition' => 'deleted=0'
);
}now you can call your model like this to disable the default scope:
MyModel::model()->disableDefaultScope()->findAll();
Have fun and thanks to Mike!
Cheers!
TAKE CARE: I don't know why, but this editor seems to make the 'behavior'-part of the classnames lowercase... of course they start with an uppercase 'B'.

Help














