SUBSCRIBE VIA RSS


Subscribe to our feed

Status Updates

  • First iPhone app nearly complete! I've been waiting for 3 weeks for Apple to finish "conducting company identity verification."
    3 days ago
  • Rainy day! Staying indoors. Creating computerized players in a simulation game that models cooperation in the work place.
    75 days ago
  • Up at 8AM, with a hot cup of coffee brought back from Cafe Lola in Ann Arbor. Will I succeed in putting in 8 billable hours in one day?
    100 days ago
  • full scale irish band outside my window playing the pipes for the past 20 minutes. pretty fun.
    109 days ago
  • listening to Kristin on Maxim Radio!
    115 days ago
  • back from an amazing meal at ouest with even more amazing company.
    115 days ago
  • wondering how so many online tshirt companies stay in business--ones that sell shirts with funny messages, i never see them in real life
    122 days ago

Topics

TWITTER

The old fashioned way

RECENT TUNES

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

3 Responses to “Propel Transactions with Symfony”

  1. 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

  2. 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

1 Trackback(s)

  1. Mar 2, 2008: rpsblog.com » A week of symfony #61 (25 february -> 2 march 2008)

Post a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word