I'm struggling with a very strange problem, and I cannot seem to fix it.
Short version
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:
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
On that particular line, I try to get to the child table of the current table
Long version
I'm using Kohana + Doctrine. I have three tables where I want to get the results from.
I have two situations:
- Show all childs of a particular table
- Show some childs of a particular table
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.
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.
Is it a problem to execute the query from within a 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();
}
The view where this code is used:
<?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;?>