How to validate composite unique key?

My table have the following informations: company, year and number. All them are part of a unique key.

I know how to validate a basic unique key, but how can I make rules() to validate my key?

Thx!

You can change the return value of the rules method of your model.



public function rules()


    {


        return array(


            array('attriubteThatNeedsToBeUnique', 'myValidator'),


    );


    }


 


    public function myValidator($attribute,$params)


    {


        //do your check here


    }


More information you can find in the documentation: http://www.yiiframew…uide/form.model

In Yii, we have



public function rules()


    {


        return array(


            array('myAttribute', 'unique'),


    );


}





I am thinking that Yii have somehing like



public function rules()


    {


        return array(


            array(array('attr1', 'attr2', 'attr3'), 'unique'),


    );


}





But this don't work.

The uniqueness check for composite key is not supported currently. We may consider implementing it in 1.1. Could you please create a ticket for this? Right now, you will need to implement it by yourself using either a method-based or class-based validation.

Ok, thanks Qiang!