findOne() , afterFind() and scenario

Hi, this is my situation…

$model = TestModel::findOne($id);

I want to perform some action in afterFind() but only if model is in certain scenario. How can I set the scenario in this case?

I tried…

$model = new TestModel([‘scenario’ => ‘test’]);

$model2 = $model->findOne($id);

but obviously this doesn’t work. Scenarion of second model is set to “default”

Help! :)

Maybe that’s not even the right way to go. Any suggestions how to manipulate attributes on “afterFind” but only in certain situations?

For instance I want to apply some attribute formatting when I do find() on frontend, but not in backend.

I know I can do it in controller or maybe even call some method to do the formatting but this looks ugly, so I’m hoping there’s some better way to do this. Scenarios sound perfect for this, but not sure how to apply them in this case?

Any suggestions?


Unfortunately not. AfterFind() method is called before the scenario is set here in line 2.

Any other ideas?