in the Yii structure, can I use a unique validation rule to verify the uniqueness of a field in some specific state (I know there are criteria, but this condition is a bit complicated)? That is, I want to check the uniqueness of num_days by the property_id property.
Table:
NUM PROP_ID 3 4 3 5
the check should pass if I try to insert 3, 6, but a failure in the case of 3, 4
UniqueAttributesValidator, . , $this->attributename params criteria CUniqueValidator, - $this->attributename null. , , $this , UniqueAttributesValidator, .
$this->attributename
params
criteria
null
$this
sql WHERE, :
WHERE
SELECT ... WHERE (`num`=:value) AND (`prop_id`=:prop_id) ...
3, 4 3, 6. , .
()
array('field_name', 'unique'),
public function rules() { return array( array('firstKey', 'unique', 'criteria'=>array( 'condition'=>'`secondKey`=:secondKey', 'params'=>array( ':secondKey'=>$this->secondKey ) )), ); }
, .