2010-02-11 21 views
0

我正在努力解決一個非常奇怪的問題,而且我似乎無法修復它。從Doctrine_Record執行查詢時無法加載相關表格

短版
當我從Doctrine_Record內執行查詢,它只是似乎不工作時,我試圖讓相關表。我得到一個異常:

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

這一特定線路上,我嘗試

我使用的Kohana +學說才能到當前表

龍版的子表。我有三張表,我想從中獲得結果。

我有兩種情況:

  1. 顯示
  2. 顯示特定表

的一些孩子的對於第一種情況的特定表的所有孩子的,我已經把一種在模型,它執行(原則)查詢並返回結果。這工作正常。

對於第二種情況,將方法添加到父原則記錄中以獲取所有內容,但隨後進行過濾,看起來很方便。但是,當我執行該查詢時,我得到或未知的類異常,或試圖獲得對非對象錯誤的引用(取決於我確切執行/返回的內容)。試圖找到問題的根源,我甚至只是返回應該工作的第一個方法的結果,但即使在那裏,我也得到相同的錯誤。

從Doctrine_Record中執行查詢是否有問題?

Doctrine_Record:

class Issue_History extends BaseIssue_History 
{ 
    public function getUserSafeItems() 
    { 
     $model = new Issue_History_Model(); 
     return $model->fromIssueId(0); 
    } 
} 

Issue_History_Model:

public function fromIssueId($issue_id) 
{ 
    $q = Doctrine_Query::create() 
     ->from("Issue_History IH, IH.Issue_History_Items IHI, IHI.Change_Types") 
     ->where("IH.issue_id = ?", 3) 
     ->orderBy("IH.date"); 

    return $q->execute(); 
} 

在使用該代碼的觀點:

<?foreach($model->issue_history as $history): //$issue_history is the result of Issue_History_Model->fromIssueId($id)?> 
<div class="changeItem"> 
    <h4>Bijgewerkt door <?=$history->User->name?> <?=datehelper::getRelativeTime($history->date)?></h4> 
    <ul> 
     <? 
      if($model->showNonUserChanges || $history->hasUserSafeItems()): //In the case of the error, the first condition is false, but the last is true?> 
      $history_items = $model->showNonUserChanges ? $history->Issue_History_Items : $history->getUserSafeItems()->Issue_History_Items?> 
      <?foreach($history_items as $history_item):?> 
      <li><?=sprintf($history_item->Change_Types->text, $history_item->old_value, $history_item->new_value)//Exception happens here?></li> 
      <?endforeach?> 
     <?endif;?> 
    </ul> 
</div> 
<?endforeach;?> 

回答

0

要查看你從學說得到了什麼數據,你可以這樣做:

var_dump($history->toArray()); 
var_dump($history_items->toArray()); 

你沒有提供你瑪的,所以我不能說更多..

+0

一些幫助,我通過簡化查詢解決了這個問題。 – Ikke 2010-02-12 11:05:51