Unique rule for two primary keys

Hi,

I tried this code to validate the uniqueness of two primary keys:


public function rules() {

    return array(

        array('firstKey', 'unique', 'criteria'=>array(

            'condition'=>'`secondKey`=:secondKey',

            'params'=>array(

                ':secondKey'=>$this->secondKey

            )

        )),

    );

}

However, this only works on updating. On insert I receive this exception: CDbException. CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed:

are you trying to make them unique together?

i.e.

A + B = Unique

A + C = Unique

yes

the reason it works on update because there is record available in the database, when you inserting/creating the data there is not record with that information, your firstKey, secondKey are still memory

hi

use custome validate function.

see this link :

My link