Get Parent Table Record Id In Child Table Using Foreign Key

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.

So i want when i enter records in parents table the id of each records automatically goes in to child table.

i know about trigger but i dont want to use them

how can i do this?

Please help

you can take care of this in you sitecontroller#create when you create your parent record you can add a record in your child table as well but your bet best is triggers

EDIT:

alternatively you can make use of AR hooks

how can i do this in site controller can you give me little bit hit and as i said i dont want to use trigger they are not very handy to manage thanks for your reply

hi perks try this article has documentation AR hooks the one you need is afterSave

http://www.yiiframework.com/doc/guide/1.1/en/database.ar#customization

EDIT:

Code Example

Thanks alirz23 You are great