问题
I'm setting up the required rule based on condition but looks like it abuse the condition. what I am I went wrong ???
['objective_id','required','when'=>function($model){ return $model->subcategory_id == 3; }],
回答1:
I figure out my problem, the code is right but I forgot that I'm working with ActiveRecord. I solved it by set up the field "objective_id" to null in a database table
来源:https://stackoverflow.com/questions/54228799/conditional-validation-in-yii2-0-fail