Yii validation rule - unique
php, yii
Solution
Check out UniqueAttributesValidator, and also this answer. In the links you'll see that they have used `$this->attributename` for the `params` array of the `criteria` option of CUniqueValidator, but for some reason `$this->attributename` was `null` for me. I believe that this is because the `$this` is not being passed correctly to the validator, so anyway it would be best to use the UniqueAttributesValidator class, because it has been made just for these kinds of situations.
The resulting sql will have a `WHERE` clause like this:
SELECT ... WHERE (`num`=:value) AND (`prop_id`=:prop_id) ...
which will easily fail for 3, 4 and pass for 3, 6. So it should work for your situation.
Problem
in Yii framework, can I use unique validation rule to check uniqueness of an field within some condition (I know there is criteria, but this condition is a bit tricky)? Ie, i want to check num_days unique by property_id. table: ``` NUM PROP_ID 3 4 3 5 ``` validation should pass in case i try insert 3, 6, but fail in case of 3, 4