Detach a behavior from a model

I have model A that implements BehaviorX (that extends CActiveRecordBehavior). Model B extends Model A, but I need to detach BehaviorX for that class.

$this->detach doesn’t work.

Code:

Model A




class Model_A extends CActiveRecord

{

  public function behaviors(){

          return array( 

                'BehaviorX' => array(

                 // parameters here

                );

      }           

}



Model B




class Model_B extends Model_A

{

public functon init() { // this doesn't work

$this->detach('BehaviorX');

return parent::init();

}

 

public function behaviors(){ // this works but... sucks <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />

                $arr = parent::behaviors(); //retrieve behaviors array 

                unset($arr['BehaviorX']); // remove item with 'BehaviorX' index from behaviors array

                return ($arr); //returns array without BehaviorX item.

        }   

}



Is there a better ‘Yii way’ to detach a behavior from a model? tia

danilo

Something like this shuld work:




$this->detachBehavior('BehaviorX');;



or eventually(see that I changed order):




public functon init() { 

$myObj = parent::init();


$myObj->detach('BehaviorX');

return myObj;

}



Sorry, in my code I wrote :




$this->detach('BehaviorX');



but I tried also with your solution, with no luck:




$this->detachBehavior('BehaviorX');



Also tried with $this->disableBehavior(‘BehaviorX’);

No luck