(posted on symfony forums: general, 1.3/1.4 branch)
How can I put several updates of objects inside of one transaction in
Symfony?

For example:

I have a car object which is allowed only one picture. The owner of
the record edits the record about the car and supplies the name of
another file foto (uploaded on a different page). S/he also updates
some textual information.

So:

change outgoing photo's 'deleted_timestamp' field to a date from NULL
change incoming photo photo's NULL 'car_id' to edited car object's id
update the car object.

It works with no transaction around them, but 'with no transaction'
obviously. The only relevant database constraint is that the photo's
records' 'car_id' is a foreign key to car table and it's set to ON
DELETE CASCADE to get rid of the photos. Each car can have only one
photo, but the photos' records are made 'deleted' so that a garbage
collection system deletes the actual files on the hard drive. This is
because it's not possible to put a file deletion in a transaction
Smile [I know I could either move it or rename it with a suffix or
prefix, but I'm also trying to learn about symfony and transactions.)

The way I'm trying it below doesn't work. I don't get any exceptions,
warnings, or error messages.
---------------------------------------:
(LOTS of error checking taken out)
(This is in the car's action file update action)

      $context=$this->getContext();
      $connection = $context->getDatabaseConnection('doctrine');
        try{
          $connection->beginTransaction('SERIALIZABLE');

            $this->currentMediaObject['deleted_tz'] = date('Y-m-d
H:i:s');
            $this->currentMediaObject->save();

            $this->incomingMediaObject['car_id'] = $this->carForm-
>getValue('id');
            $this->incomingMediaObject->save();

          $this->Carform->save();
          $connection->commit();
-- 
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-us...@googlegroups.com.
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en.


Reply via email to