Sometimes you want your validation rules to be just a little bit more than the standard options available to you like ‘numeric’, ‘length’ or ‘safe’.
array('username', 'unique', 'className' => 'User');
But sometimes you want unique to be more intelligent with it’s unique validation…
array('username', 'unique', 'className' => 'User', 'criteria' => array(
'condition' => 'active = 1',
)
)
The test above will only match when username is not unique AND active = 1. In the case of unique, criteria you define is appended to the existing check which would always take place.
Very useful post
ReplyDelete