Conditional Validation In Yii2.0 fail

2019-09-20 09:28发布

问题:

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



标签: yii2