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 {
$con->begin();
UserFavoriteEventPeer::deleteAllForEvent($this->getId());
EventPeer::doDelete($this, $con);
$con->commit();
} catch (PropelException $e) {
$con->rollback();
throw $e;
}



Is this meant to be overriding the Event::Delete method? I would expect so, but you’re not very clear…
By hackel on Mar 19, 2008
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.
By Scott Meves on Mar 19, 2008