title: sfContext::getInstance()->getUser() not working in createQuery from validator
body: <p>Now: resolved - no reproducible anymore</p>
  
  <p>For some specific application security, I have the following createQuery function on a table, ie you can only access  the table record if you have the "Administrator" credential or if you are the user that is stored in the MembershipDelegate relation.</p>
  
  <pre><code>class OrganisationTable extends Doctrine_Table
  function createQuery($alias = ''){
  
      if (!$alias){
          $alias = 'o';
      }
  
      $query = parent::createQuery($alias);
      try {
          $user = sfContext::getInstance()-&gt;getUser();
      }catch(Exception $e){
          if ($e-&gt;getMessage() == 'The "default" context does not exist.'){
              return $query;
          }else{
              throw $e;
          }
      }
  
      if ($user-&gt;hasCredential('Administrator')){
          //all good
  
      }else{
  
  
          $userId = $user-&gt;getAttribute('userId');
          print "&lt;!--testaa ".print_r($user-&gt;getCredentials(),1).'--&gt;';
          $query-&gt;
          leftJoin("$alias.MembershipDelegate mdelsec")-&gt;
          addWhere ("mdelsec.joomla_user_id=$userId");
      }
  
      return $query;
  }
  </code></pre>
  
  <p>This seems to work fine at all levels, however there is a choice validator for which the $user object seems to come back empty</p>
  
  <pre><code>    /**
       * Person form base class.
       *
       */
       ...
      abstract class BasePersonForm extends BaseFormDoctrine
      {
        public function setup()
        {
          $this-&gt;setWidgets(array(
  
      ...
            'organisation_id'                          =&gt; new sfWidgetFormDoctrineChoice(array('model' =&gt; $this-&gt;getRelatedModelName('Organisation'), 'add_empty' =&gt; true)),
  
  
      class PersonForm extends BasePersonForm{
  
          public function configure(){
  
              $this-&gt;widgetSchema['organisation_id']-&gt;setOption('renderer_class', 'sfWidgetFormDoctrineJQueryAutocompleter');
              $this-&gt;widgetSchema['organisation_id']-&gt;setOption('renderer_options', array(
              'model' =&gt; 'Organisation',
              'url' =&gt; NZGBCTools::makeUriJoomlaCompatible(
                      sfContext::getInstance()-&gt;getController()-&gt;genUrl('organisation/jsonList'))
              ));
              $this-&gt;validatorSchema['organisation_id']-&gt;setOption('required',false);
  </code></pre>
  
  <p>is there any other way to get the user object in the model?</p>
  
  <p>This approach to row level security may not be MVC by-the-book, but is IMO safer and superior than implementing the same security concepts in the actions:</p>
  
  <ul>
  <li>It can be used with out of the box admin-generator modules</li>
  <li>It is much harder to forget to implement it somewhere</li>
  <li>It may at times not require any credentials, only Super Admin access</li>
  </ul>