setter not dispatch

Hello.

I’m trying to create a setter method for my model and try to call it from my controller:

in controller file:


$_model = $this->loadModel();

$_model->etnia = 19;

$_model->save();

in model file:


   protected function setEtnia()

   {

       Yii::trace("Test","file");        

   }

So…, the setter method is not fired when 19 is assigned to “etnia” field. I’ve achieved it only if I create this overriding __set() method in model file:


public function __set($name,$value)

    {

        $setter='set'.$name;

        if(method_exists($this,$setter))

        {

                $this->$setter();

        }

        parent::__set($name,$value);

    }



Then, the setEtnia() method is fired.

What am I doing wrong??

This is by design. Database fields should be handled in validators for validation or in beforeX/afterX methods for modification.

// See here for explanation from core developer.