This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » legacy support » symfony 1.2 » insert record into two tables at the same time
insert record into two tables at the same time [message #102450] Wed, 14 July 2010 09:48 Go to next message
cgithinji  is currently offline cgithinji
Messages: 4
Registered: June 2010
Junior Member
Hi all,

am i newbie to symfony and critically in need of help.
i have two tables: exam and examapprove. i want when a user creates a new exam the exam_id is also inserted into the examapprove table. how can i achieve this and from which file: Exam.class.php or ExamApprove.class.php?


Thanks in advance
Re: insert record into two tables at the same time [message #102452 is a reply to message #102450 ] Wed, 14 July 2010 10:25 Go to previous messageGo to next message
johnny.lattouf  is currently offline johnny.lattouf
Messages: 44
Registered: September 2009
Member
I assume you are using Doctrine.

You can add an event on exam insertion in Exam.class.php in order to add the exam id in the ExamApprove.class.php

Exam.class.php
public function postInsert($event)
{
  $exam_approve = new ExamApprove();
  $exam_approve->setExamId($this->getId());
  ...
  $exam_approve->save();
}


Johnny Lattouf
Re: insert record into two tables at the same time [message #102453 is a reply to message #102450 ] Wed, 14 July 2010 10:33 Go to previous messageGo to next message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
You'll need to confirm if you're using Propel or Doctrine. Some platform details are often helpful too - be accurate in your problem reports!


Remember Palestine
Re: insert record into two tables at the same time [message #102456 is a reply to message #102450 ] Wed, 14 July 2010 11:13 Go to previous messageGo to next message
cgithinji  is currently offline cgithinji
Messages: 4
Registered: June 2010
Junior Member
am using the doctrine platform. where do i call the postInsert() that johnny.lattouf has suggested.
Re: insert record into two tables at the same time [message #102458 is a reply to message #102450 ] Wed, 14 July 2010 11:19 Go to previous message
johnny.lattouf  is currently offline johnny.lattouf
Messages: 44
Registered: September 2009
Member
You don't do that, it will be called after a new exam creation.

You can check this:

http://www.doctrine-project.org/projects/orm/1.2/docs/manual /event-listeners/en


Johnny Lattouf
Previous Topic:propel+oracle+build problem
Next Topic:Problem with Left Join
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software