我正在尝试使用Paginate类的学说来获取一些任务。
$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
}
我的问题是,为什么$ task是一个数组?
答案 0 :(得分:3)
DQL中选定的priority.id
导致此问题,因为ORM必须将其检索为标量结果。访问$task[0]
应该会为您提供fetch-joined task
个对象,而$task['priority_id']
会为您提供代表priority.id
的标量。