title: symfony 1.4, $this->save() and mysql insert triggers
body: <p>I have an on-insert trigger that updates a product code in a table, based on a customer's most recent code, stored in another table.</p>
  
  <p>With symfony and Propel, I am doing the following (truncated unnecessary fields)</p>
  
  <pre><code>// actions.class.php
  $lineitem = new LineItem();
  $lineitem-&gt;setCustomerId( $customerId );
  
  $thisProduct = ProductPeer::cacheProduct($orderDetails);
  $lineitem-&gt;setCode($thisProduct-&gt;getCode()); // this should be fetching and setting the auto_code, inserted from the trigger.
  $lineitem-&gt;save();
  </code></pre>
  
  <p>The cacheProduct function (part of ProductPeer) below</p>
  
  <pre><code>// ProductPeer.php
  // auto_code field in DB left blank, ready to be written to by the trigger
  // cacheProduct function
  public static function cacheProduct($orderDetails)
  {
      $product = new Product();
      $product-&gt;setName( $orderDetails-&gt;getName() ); 
      $product-&gt;setCustomerCode( $orderDetails-&gt;getCustomerCode() );
      //$product-&gt;setCode(); // this will be set by the TRIGGER on insert.
      $product-&gt;save();
  
      return $product-&gt;getId();
  }
  </code></pre>
  
  <p>So the problem is that the product is being inserted, and the trigger is being run successfully, but Symfony is never aware of the newly inserted 'code' value. Running a fresh <strong>ProductPeer::retrieveByPK()</strong> still shows an empty 'code' field.</p>
  
  <p>So in essence, at all points, <strong>$lineitem->getCode()</strong> returns null.</p>
  
  <p>I've tried wrapping this in transactions, but it shouldn't be necessary ... and also there is potential for this to be in a loop and I don't want to open and close transactions repeatedly unless absolutely necessary.</p>
  
  <p>1) When does a MYSQL trigger actually run ... on <strong>$xxx->save()</strong>? At the end of the script?
  2) How can I access this value post-trigger, while still in the same script?</p>
  
  <p>Solution found, thank you :)
  Working with Propel version 1.4.8 or greater</p>