Usefulness of scenarios

I want to see a few cases where form scenarios are handy.

At this point of view, I see them as unnecessary (thus harmful) overhead. Different forms serve different scenarios, so instead of adding new scenarios to handle, it’s more logical to add a form model.

I can only think of crud operations, where the same form is used to create and update a record.

Did I overlook something and misunderstand the very concept of scenarios? Could you tell me an example when scenarios get useful?

Creating a new model is not always optimal as you might have some logic in beforeSave()/beforeValidate(), etc that needs to be executed across the different scenarios. But if you create a new model for each scenario then you may have to duplicate this code (redundant)


In one of my forms I have a checkbox. When its checked then some extra fields appear in the form and should be validated, some other fields disappear and should not be validated. So in the controller I check if the checkbox is set and then decide which scenario is used for validation.

Using scenarios seemed the most elegant way to solve this.

So scenarios enable me to invisibly reuse my methods within a single form model. Great!

Jonah, I’ve subscribed your blog right away! I wish you and your blog the best!


Another wonderful point! I should have thought this way. Thank you, too.