2013-02-27 78 views
1

我想使用教義分頁類來獲取一些任務。學說分頁器迭代是一個1對象的數組

$qb = $this->getEntityManager() 
      ->createQueryBuilder() 
      ->select('DISTINCT task, priority, company, invoice') 
      ->addSelect('priority.id as priority_id') 
      ->from('TekniqSD4Bundle:task', 'task') 
      ->leftJoin('task.slips', 'slips') 
      ->leftJoin('task.comments', 'comments') 
      ->leftJoin('task.files', 'files') 
      ->leftJoin('task.steps', 'steps') 
      ->leftJoin('task.status', 'status') 
      ->join('task.invoice', 'invoice') 
      ->join('task.priority', 'priority') 
      ->join('invoice.company', 'company'); 

$query = $qb->getQuery() 
      ->setMaxResults(2) 
      ->setFirstResult($offset); 
$paginator = new Paginator($query, true); 
foreach($paginator as $task){ 
    var_dump($task); //this spits out an array containing 1 task 
} 

我的問題是,爲什麼$任務數組?

回答

3

在您的DQL中選擇的priority.id會導致此問題,因爲ORM必須將其作爲標量結果進行檢索。訪問$task[0]應該給你fetch-joinedtask的對象,而$task['priority_id']給你的標量代表priority.id

+0

我甚至沒有意識到那裏,謝謝你好,先生。 – Trololololol 2013-02-27 21:09:38