Author Topic: How to Add Parent Table Record Id In Child Table Using Foreign Key  (Read 4918 times)

rahul

  • Newbie
  • *
  • Posts: 16
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

perks

  • Newbie
  • *
  • Posts: 11
Re: How to Add Parent Table Record Id In Child Table Using Foreign Key
« Reply #1 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....

phpdeveloper

  • Newbie
  • *
  • Posts: 39
Re: How to Add Parent Table Record Id In Child Table Using Foreign Key
« Reply #2 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();
   }

perks

  • Newbie
  • *
  • Posts: 11
Re: How to Add Parent Table Record Id In Child Table Using Foreign Key
« Reply #3 on: October 20, 2012, 12:23:17 PM »
ahhh i see Thanks Phpdeveloper you are Rock.............

 

X

Do you know?

By participating in our community you can get free top level domain as well learn about Search Engine Optimization, Server management and more..
Join Now!