title: Adding attribute options programmatically are not available for use immediately
body: <p>I'm creating Magento attribute options via a script, but I need to then be able to get the new ID and use it straight away in the same script.</p>
  
  <p>At the moment it's not pulling the id through - if I kill the script and re-start it it picks up the created option and returns the ID, but not as part of the same script.</p>
  
  <p>Here is the code I am using:</p>
  
  <pre><code>   $attr = Mage::getModel('catalog/product')-&gt;getResource()-&gt;getAttribute($key);
     if ($attr-&gt;usesSource()) {
             $vattr_id = $attr-&gt;getSource()-&gt;getOptionId($value);
     }else{
             echo "No Source";
             $vattr_id = false;
     }
  
  
  if($vattr_id){
          return $vattr_id;
  }else{
  
          $attr_model = Mage::getModel('catalog/resource_eav_attribute');
          $attr = $attr_model-&gt;loadByCode('catalog_product', $key);
          $attr_id = $attr-&gt;getAttributeId();
  
          $option['attribute_id'] = $attr_id;
          $option['value'][$value][0] = $value;
          $option['value'][$value][1] = $value;
  
          $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
          $setup-&gt;addAttributeOption($option);
          $attr = Mage::getModel('catalog/product')-&gt;getResource()-&gt;getAttribute($key);
          if ($attr-&gt;usesSource()) {
                 $vattr_id = $attr-&gt;getSource()-&gt;getOptionId($value);
                  echo "AttrID: $vattr_id";
          }
  
  }
  </code></pre>
  
  <p>Running this (with the required <code>Mage::app()</code> etc), creates the option, you can see it in the Magento back end, but the <code>$vattr_id</code> is <code>NULL</code>. If I reload the script, then it finds the attribute option in that first block as it should.</p>
  
  <p>I guess it's something to do with how Magento is caching the models, but not sure where I need to look to clear these?</p>