Webmaster's Community

Designing and Development => Programming => Topic started by: rahul on October 20, 2012, 08:34:34 AM

Title: How to Add Parent Table Record Id In Child Table Using Foreign Key
Post by: rahul on October 20, 2012, 08:34:34 AM
Hello,
I have one parent & child table and i have make relation ship using a foreign key. Primary key in parent table is forein key in child table.

now  i want when i enter records in parents table the id of each records automatically goes in to child table.
 
any help will be appropriate
Title: Re: How to Add Parent Table Record Id In Child Table Using Foreign Key
Post by: perks on October 20, 2012, 10:54:49 AM
i want to achieve the same in yii framework
can some one help me out

Thanks in Advance....
Title: Re: How to Add Parent Table Record Id In Child Table Using Foreign Key
Post by: phpdeveloper on October 20, 2012, 12:20:23 PM
hi  perks
you can make use of AR hooks  or you can make changes in your controller like this
Code: [Select]
public function afterSave() {
     
      $model = new ChildModel();
      $model->parendID = $this->id;
      $model->save;
      return parent::afterSave();
   }
Title: Re: How to Add Parent Table Record Id In Child Table Using Foreign Key
Post by: perks on October 20, 2012, 12:23:17 PM
ahhh i see Thanks Phpdeveloper you are Rock.............