raoul2000 / yii2-workflow

A simple workflow engine for Yii2
BSD 3-Clause "New" or "Revised" License
171 stars 48 forks source link

Validation on dependant model #67

Closed ferllings closed 3 years ago

ferllings commented 3 years ago

Hi,

Is it possible to use the validation events on a secondary model?

I have my main model A, witch holds the workflow status. But I also have a secondary B model, with additional fields that require validation on the A workflow events.

raoul2000 commented 3 years ago

Hi, the validation based on workflow events only applies to the model that holds the statusattribute (the one who triggers the validation when its status changes). That being said, Yii2 allows you to create your own validator and so, assuming you have access to the secondary model from the primary model, you could perform any validation you want in this custom validator (including validating attributes owned by the secondary model). Again this is outside of the yii2-workflow scope but could be addressed by Yii2 Validation features.

Hope it helps 😎

ferllings commented 3 years ago

Thanks, it does help. !