loadMultiple - models scenario

Hi,

I’d like to change models scenario while loading data with loadMultiple. Is there an easier way than this?:




$model = MyModel::find()->all();

if($model != null) {

  foreach($model as &$m) {

    $m->scenario = "my_scenario";

  }

}


if(Model::loadMultiple($model, Yii::$app->request->post())) {

...

}



Not tested but isn’t scenario attribute of the model? Can’t you do massive assignment just as post?

Model::loadMultiple($model, [‘scenario’=>‘your_scenario’]);

Yes it is, only it has to be set ‘safe’ in model class. Thanks :)

Now I’m thinkig, passing this value in a form might be dangerous - user can change this attribute. If there is no other way I’ll stay with my first idea.

Thx

Just make a function in validation and set fixed list of scenarios as whitelist