Suppose that a 'user' belongs to a 'forum'. A 'forum' should be unique thus I can code as
public function rules()
{
return array(
(snip)
array('forum', 'unique'),
);
}
in my model class extended from CActiveRecord, and it is working fine.
On the other hand, 'user' may be unique in a certain 'forum' but not unique throughout the table, since a 'user' can belong to any 'forum'.
Then, I would like to code as
public function rules()
{
return array(
(snip)
array('user', 'unique', <some condition here like 'forum = xxx'>),
);
}
,but I found it may not have this functionarity from my investigation of the code in CUniqueValidator class as below.
protected function validateAttribute($object,$attribute)
{
(snip)
if($this->caseSensitive)
$exists=$object->exists("$columnName=:value",array(':value'=>$value));
else
$exists=$object->exists("LOWER($columnName)=LOWER(:value)",array(':value'=>$value));
BTW, I will be able to extend CUniqueValidator for myself, but I think it is better to have this functionarty within CUniqueValidator.
Thanks in advance.