I don’t think this already exists in the current unique and exist validators, but it would be nice if you could add an extra condition to those validators. I’m at the start of a project and i already needed this twice, eventually i had to write my own validator (InlineValidator) for it.
[['username'], 'unique', 'targetClass' => '\frontend\models\User', 'targetAttribute' => 'username', 'targetWhere' => ['accountStatus' => 0]],
So the query executed for those validators become:
SELECT 1 FROM `user` WHERE (accountStatus = 0) AND (`username`='test')
Instead of this:
SELECT 1 FROM `user` WHERE `username`='test'