I have setup a unique constraints such as below
[['pname', 'created_by'], 'unique', 'targetAttribute' => ['pname', 'created_by'], 'message' => 'Project Name already in use'],
However, when the condition is met, instead of throwing an error message I get Database error - basically the validation is not firing. The debug logs show this SQL being executed to validate:
SELECT EXISTS(SELECT * FROM
sometable WHERE (
pname='New Project') AND (
created_by IS NULL))
I suppose the explanation here is that the behaviors (to populate created_by) kicks in after the validation, hence this exception is not handled gracefully. FYI, the created_by has a numeric value in the insert. Anyone else has thoughts or workarounds?