我可以通过内部连接轻松查询
$qb = $this->createQueryBuilder('r')
->innerJoin('UserBundle:User', 'u')
->where('r.nick = u.id')
->andWhere('r.odobera=:id')
->setParameter('id', $id)
->orderBy('r.time', 'DESC')
->setMaxResults(50);
return $qb->getQuery()->getResult();
应该是一个查询吧?但在探查器中我有
SELECT t0.username AS [...] FROM users t0 WHERE t0.id = ? LIMIT 1
Parameters: [1465]
[Display runnable query]
Time: 1.79 ms [ Explain query ]
SELECT r0_.id AS id0, [...] FROM requests r0_ INNER [...] ORDER BY r0_.time DESC LIMIT 50
Parameters: [1465]
[Display runnable query]
Time: 0.67 ms [ Explain query ]
SELECT t0.username AS username1, [...] FROM users t0 WHERE t0.id = ?
Parameters: ['2072']
[Display runnable query]
Time: 0.64 ms [ Explain query ]
SELECT t0.username AS username1, [...] FROM users t0 WHERE t0.id = ?
Parameters: ['2386']
[Display runnable query]
Time: 0.50 ms [ Explain query ]
SELECT t0.username AS username1, [...] FROM users t0 WHERE t0.id = ?
Parameters: ['79']
[Display runnable query]
Time: 0.50 ms [ Explain query ]
SELECT t0.username AS username1, [...] FROM users t0 WHERE t0.id = ?
Parameters: ['2432']
[Display runnable query]
Time: 0.50 ms [ Explain query ]
SELECT t0.username AS username1, [...] FROM users t0 WHERE t0.id = ?
Parameters: ['40']
[Display runnable query]
Time: 0.52 ms [ Explain query ]
SELECT t0.username AS username1, [...] FROM users t0 WHERE t0.id = ?
Parameters: ['2090']
[Display runnable query]
Time: 0.46 ms [ Explain query ]
SELECT t0.username AS username1, [...] FROM users t0 WHERE t0.id = ?
Parameters: ['1044']
[Display runnable query]
Time: 0.51 ms [ Explain query ]
SELECT t0.username AS username1, [...] FROM users t0 WHERE t0.id = ?
Parameters: ['27']
[Display runnable query]
Time: 0.54 ms [ Explain query ]
每条记录的每个“加入”一个查询...为什么?
PS:这篇文字只是为了让这篇文章更长,因为我不能提交“只是”这么多细节的问题..但我认为我的问题得到了很好的解释。顺便说一句:我问朋友,他有类似的问题)