Hierarchy scenario in Active Record

To me, scenario is useful. For example when writing different scenarios at the validation rules() or events(beforeSave, afterSave) in Active Record. But when the Active Record become complex the number of scenarios become more and more. When there are too many scenarios, I think it would be better if we can just group some of scenarios into one name, and we only need to define that name

for example like this code:


<?php


public function scenarios()

{

            return array(

                 'generalScenarios'=>array('registration','changeProfile'),

            );

}


public function rules() {

		return array(

			array('name, username', 'required', 'on'=>'generalScenarios'),

                );

}


public function afterSave()

{

           if ($this->checkScenario('generalScenarios')){

                //do something

           }

}

Good idea, but it’s more likely an extra feature, not something that is implemented in the first releases, because it isn’t really a design change.

A great idea to finally get confused :)

Much more clearly:




public function rules() {

                return array(

                        array('name, username', 'required', 'on'=>'registration, changeProfile'),

                );

}



and




public function afterSave()

{

           if($this->scenario==='registration' || $this->scenario==='changeProfile')

           {

                //do something

           }

}



Because when then need:




public function afterSave()

{

           if($this->scenario==='registration')

           {

                //do some thing

           }


           if($this->scenario==='changeProfile')

           {

                //do other thing

           }

}



You will do degroup, and I just change my code.

But if you want even so grouping than you can do it right now:




public function rules() {

                $generalScenarios=array('registration', 'changeProfile');


                return array(

                        array('name, username', 'required', 'on'=>$generalScenarios),

                );

}



Not more. A new method scenarios() for scenario grouping… hm…