title: How should I do post persist/update actions in doctrine 2.1, that involves re-saving to the db?
body: <p>Using doctrine 2.1 (and zend framework 1.11, not that it matters for this matter), how can I do post persist and post update actions, that involves re-saving to the db?</p>
  
  <p>For example, creating a unique token based on the just generated primary key' id, or generating a thumbnail for an uploaded image (which actually doesn't require re-saving to the db, but still) ?</p>
  
  <hr>
  
  <h2><em>EDIT - let's explain, shall we ?</em></h2>
  
  <p>The above is actually a question regarding two scenarios. Both scenarios relate to the following state:  </p>
  
  <blockquote>
    <p>Let's say I have a <em><code>User</code></em> entity. When the object is flushed after it has been marked to be persisted, it'll have the normal auto-generated id of mysql - meaning running numbers normally beginning at 1, 2, 3, etc..<br>
    Each user can upload an image - which he will be able to use in the application - which will have a record in the db as well. So I have another entity called <em><code>Image</code></em>. Each <em><code>Image</code></em> entity also has an auto-generated id - same methodology as the user id.</p>
  </blockquote>
  
  <p>Now - here is the scenarios:</p>
  
  <ol>
  <li><p>When a user uploads an image, I want to generate a thumbnail for that image right after it is saved to the db. This should happen for every new or updated image.<br>
  Since we're trying to stay smart, I don't want the code to generate the thumbnail to be written like this:  </p>
  
  <blockquote>
    <p>$image = new Image();<br>
    ...<br>
    $entityManager->persist($image);<br>
    $entityManager->flush();<br>
    callToFunctionThatGeneratesThumbnailOnImage($image);</p>
  </blockquote>
  
  <p>but rather I want it to occur automatically on the persisting of the object (well, flush of the persisted object), like the <code>prePersist</code> or <code>preUpdate</code> methods.</p></li>
  <li><p>Since the user uploaded an image, he get's a link to it. It will probably look something like: <code>http://www.mysite.com/showImage?id=[IMAGEID]</code>.<br>
  This allows anyone to just change the imageid in this link, and see other user's images.<br>
  So in order to prevent such a thing, I want to generate a unique token for every image. Since it doesn't really need to be sophisticated, I thought about using the md5 value of the image id, with some salt.<br>
  But for that, I need to have the id of that image - which I'll only have after flushing the persisted object - then generate the md5, and then saving it again to the db.</p></li>
  </ol>
  
  <p>Understand that the links for the images are supposed to be publicly accessible so I can't just allow an authenticated user to view them by some kind of permission rules.  </p>