How To Do See If The Field Values Are Unique In A Table

I have a model class file called


test.php

. I have two fields -


Function type

and


Service Type

. So, now I want to see that both


Function type

and


Service Type

are unique. i.e


Function type

and


Service Type

cannot be the same in more than one row.

I'm using the create and update function for this. I want both the functions to see if 

Function type

and


Service Type

are repeated, then don’t save it and if not repeated then save it.

I'm using the below example to illustrate the rows -  

ID Function type Service Type

1                    2                3


2                    4                5


3                    7                8

How can I do this validation before saving. Please guide me on this.

Try this

public function rules() {

return array(


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


        'condition'=>'`ServiceType`=:ServiceType',


        'params'=>array(


            ':ServiceType'=>$this->ServiceType


        )


    )),


);

}

Hi,

Following code will help to keep fieldvalues unique.

public function rules()

{


	// NOTE: you should only define rules for those attributes that


	// will receive user inputs.


	return array(


		array('username', 'unique'),


	);


}

Are you looking for the same?

Thanks

chandran nepolean