title: Can not load related tables when executing query from Doctrine_Record
body: <p>I'm struggling with a very strange problem, and I cannot seem to fix it.</p>
  
  <p><strong>Short version</strong><br>
  When I execute a query from within a Doctrine_Record, it just doesn't seem to work when I try to get a related table. I get an Exception:</p>
  
  <blockquote>
    <p>error: Uncaught PHP Error: Trying to get property of non-object in file 
    D:/Tools/Development/xampp1.7/htdocs/x-interactive/xibits/application/views/issues/changeList.php
    on line 23</p>
  </blockquote>
  
  <p>On that particular line, I try to get to the child table of the current table</p>
  
  <p><strong>Long version</strong></p>
  
  <p>I'm using Kohana + Doctrine. I have three tables where I want to get the results from.</p>
  
  <p>I have two situations:  </p>
  
  <ol>
  <li>Show all childs of a particular table</li>
  <li>Show some childs of a particular table</li>
  </ol>
  
  <p>For the first situation, I have put a method in a model which executes a (doctrine) query and returns the result. This just works fine.</p>
  
  <p>For the second situation, it looked convenient to add a method to the parent doctrine record, to fetch everything, but then filtered. But when I execute that query, I get or an unknown class exception, or a trying to get a reference to a non-object error (depending on what I exactly execute/return). Trying to get to the source of the problem, I even just return the result of the first method that should work, but even there I get the same error.</p>
  
  <p>Is it a problem to execute the query from within a Doctrine_Record?</p>
  
  <p>Doctrine_Record:</p>
  
  <pre><code>class Issue_History extends BaseIssue_History
  {
      public function getUserSafeItems()
      {
          $model = new Issue_History_Model();
          return $model-&gt;fromIssueId(0);
      }
  }
  </code></pre>
  
  <p>Issue_History_Model:</p>
  
  <pre><code>public function fromIssueId($issue_id)
  {
      $q = Doctrine_Query::create()
          -&gt;from("Issue_History IH, IH.Issue_History_Items IHI, IHI.Change_Types")
          -&gt;where("IH.issue_id = ?", 3)
          -&gt;orderBy("IH.date");
  
      return $q-&gt;execute();
  }
  </code></pre>
  
  <p>The view where this code is used:</p>
  
  <pre><code>&lt;?foreach($model-&gt;issue_history as $history): //$issue_history is the result of Issue_History_Model-&gt;fromIssueId($id)?&gt;
  &lt;div class="changeItem"&gt;
      &lt;h4&gt;Bijgewerkt door &lt;?=$history-&gt;User-&gt;name?&gt; &lt;?=datehelper::getRelativeTime($history-&gt;date)?&gt;&lt;/h4&gt;
      &lt;ul&gt;
          &lt;?
            if($model-&gt;showNonUserChanges || $history-&gt;hasUserSafeItems()): //In the case of the error, the first condition is false, but the last is true?&gt;
            $history_items = $model-&gt;showNonUserChanges ? $history-&gt;Issue_History_Items : $history-&gt;getUserSafeItems()-&gt;Issue_History_Items?&gt;
            &lt;?foreach($history_items as $history_item):?&gt;
              &lt;li&gt;&lt;?=sprintf($history_item-&gt;Change_Types-&gt;text, $history_item-&gt;old_value, $history_item-&gt;new_value)//Exception happens here?&gt;&lt;/li&gt;
            &lt;?endforeach?&gt;
          &lt;?endif;?&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
  &lt;?endforeach;?&gt;
  </code></pre>