Set base class attribute values while loading object / creating objects yii.

I have two models which inherits from the common base class.


class Batsmen extends CPlayer{

	batsmen_id 		// model field.

	batsmen_name	// model field.


}


class Bowler extends CPlayer{

	bowler_id		// model field.

	bowler_name		// model field.


}

// Component class which serves as a base class for models batsmen and bowler models.


class CPlayer extends CActiveRecord{

	public player_id;

	public player_name;


}

I want to load the attribute values of Batsmen/Bowler to the base class CPlayer attributes while loading an object or after creating an object of Batsmen or Bowler. How can i do this?

For "loading" you can try something like this:




class Batsmen extends CPlayer{

    public function afterFind(){

        $this->player_id = $this->batsmen_id; 

        return parent::afterFind();

    }

}



For "after creating" you can try:




class Batsmen extends CPlayer{

    public function beforeValidate(){

        $this->player_id = $this->batsmen_id; 

        return parent::beforeValidate();

    }

}