Designing and Development > Programming

How to Add Parent Table Record Id In Child Table Using Foreign Key

(1/1)

rahul:
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:
i want to achieve the same in yii framework
can some one help me out

Thanks in Advance....

phpdeveloper:
hi  perks
you can make use of AR hooks  or you can make changes in your controller like this

--- Code: ---public function afterSave() {
     
      $model = new ChildModel();
      $model->parendID = $this->id;
      $model->save;
      return parent::afterSave();
   }
--- End code ---

perks:
ahhh i see Thanks Phpdeveloper you are Rock.............

Navigation

[0] Message Index

Go to full version