Subscribe to our feed

Symfony Experts

Symfony Experts
If you have an urgent question for a symfony-related issue, this is the place to ask.


Stack Overflow

The old fashioned way


February 29, 2008 – 1:45pm Propel Transactions with Symfony

It’s easy to create transactions with Propel. This can be very useful when you are deleting rows from your database from multiple tables, and want to do an “all or nothing” approach so that things don’t get messy. In this example, we want to delete an event from our database, however this event may have related rows in the user_favorite_event table, and we’d be unable to delete the event without getting a foreign key constraint error from the database. So, we first delete all the user favorites, and then delete the event. If the first query fails, we’ll rollback the deletion of the user_favorite_event rows.

$con = Propel::getConnection(EventPeer::DATABASE_NAME);
try {
	EventPeer::doDelete($this, $con);
} catch (PropelException $e) {
	throw $e;
Posted by in  Web Development   |  

5 Responses to Propel Transactions with Symfony

  1. Pingback: » A week of symfony #61 (25 february -> 2 march 2008)

  2. hackel says:

    Is this meant to be overriding the Event::Delete method? I would expect so, but you’re not very clear…

  3. Scott Meves says:

    Transactions don’t have override the Event::delete method, but in this case it does, thus the calls to $this->getId(). you could also put this type transaction into your actions if you like rather than in the object’s class.

  4. ricardo says:

    doesnt work… for one… its beginTransaction()

  5. Scott Meves says:

    It depends on what version of propel you are using. This post is from 2008. The API for transactions was changed in Propel 1.3.