Yii Framework Forum: Uniqe email - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Uniqe email Show unique email validation across multiple models Rate Topic: -----

#1 User is offline   S@ndy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 04-September 14

Posted 12 November 2014 - 06:37 AM

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)
0

#2 User is offline   Amitesh Kumar 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 75
  • Joined: 01-October 14
  • Location:India

Posted 13 November 2014 - 12:14 AM

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 .
IF you Find i am helping Or I am asking logical question which can help others also please click on the Button One Plus
0

#3 User is offline   S@ndy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 04-September 14

Posted 13 November 2014 - 12:45 AM

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.
0

#4 User is offline   Amitesh Kumar 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 75
  • Joined: 01-October 14
  • Location:India

Posted 13 November 2014 - 10:27 PM

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.yiiframew...e-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.
IF you Find i am helping Or I am asking logical question which can help others also please click on the Button One Plus
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users