Uniqe email

I am having 3-models viz: student, professional, affiliate.

Each model has a column in its table specifying email_id.

I want to validate the entered email_id is unique across all the 3 models.

Specifying the rule unique validates only within the model in which it is specified.

Is there a way to define the rules for other models in some particular model, for eg: can I define rules for affiliate and professional in student model??

Suppose the tables are as follows

tbl_student(stu_id, primary_email)

tbl_professional(pro_id, primary_email)

tbl_affiliate(aff_id, primary_email)

in tbl_professional (pro_id,(primary_email,student_email(fk from student),affiliate_email(fk from afiliate) make it unique)

then create model for tbl_professional it think it will help you .

The tables are independent of each other, so cant establish relations between them. I am trying to make a function that checks the entered email_id in each table.

I thought there can be other alternative, but thanks for the attempt!!

Do post if you have some other ways to do it.

yes there is a another way but that way is not good.

You have to make a virtual relation between that tables

[topic=‘how i can write own relation’]http://www.yiiframework.com/forum/index.php/topic/58977-how-i-can-write-own-relation/[/topic]

follow above link it will help you.

Or you don’t want make any relation then you have to check email manually something like that


public funcion checkemail()

{

   $model=new table1::->model()->find("email");/*check condition for that id */

   if($model->email)

   {

     $model2=new table2::model()->find("email");/*check condition for that id */

     if($model->email==$model->2)

     {

        $model3=new table3::model()->find("email");/*check condition for that id */

        if($model3->email==$model2->email)

        {

           echo "email already exixt";

           render("where you want");

        }

     }   

   }

} 

i hope you understand i think this will be logic but if want all email use findall and foreach loop to check all email.

but in my opinion if you want to make unique email id you have to make relation between tables either virtual or from database.