Overriding delete() method in bespoke AR

Hi,

I am overriding the standard AR delete method so that instead of using deleteByPk() it will use a new function:


public function retireByPk($pk,$condition='',$params=array())

      {

       Yii::trace(get_class($this).'.retireByPk()','system.db.ar.CActiveRecord');

       $builder=$this->getCommandBuilder();

       $criteria=$builder->createPkCriteria($this->getTableSchema(),$pk,$condition,$params);

       $command=$builder->createRetireCommand($this->getTableSchema(),$criteria);

       return $command->execute();

      }

Every table in the DB has a column called state. When something is ‘deleted’ its state changes to 2. Thats what the retireByPk function will achieve.

I need to create a new method createRetireCommand in an extension of CDbCommandBuilder however am not sure how to extend this class - what new files do I need & where in my project do I have to reference it?

Thanks,

Julian

Hi,

Just today I read about a soft delete in Yii cookbook. The way it was done is by using behavior which has some methods that update the delete state.

Hi there,

ok sure sounds good.