I am trying to check the uniqueness of the field case-insensitively as follows:

public function rules() { return [ ['model_field', 'unique', 'on' => 'organization', 'targetClass' => '\common\models\ModelClass', 'targetAttribute' => 'lower(bd_field)', 'attributes' => 'lower_model_field', } ], ]; } 

Where:

  • model_field is the model field that I want to test;
  • bd_field is a field in the database from the \ common \ models \ ModelClass model that I want to compare with to check for uniqueness, case-insensitive;
  • lower_model_field is a field in the current model, which is equal to the lower case field of model_field

Friends, help me figure out what I'm doing wrong, because it doesn't work.

  • For this case, it turned out to be easier to write your own validator. - Razzwan

1 answer 1

Everything is OK php # L109 ) if you don’t set it up $model->setScenario('organization') then it’s best to remove this check.

  • 'attributes' => 'lower_model_field' , - this line interests me. Is it possible? Not sure how it works. Attributes - this seems to be the first member of the array. Or I'm wrong? In general, I wrote already that I solved the problem with my own validator, since Built to configure could not. - Razzwan