我正在尝试限制查询结果。
$user = $this->getUser();
$following = $em->getRepository('AppBundle:Follower')->findBy(array(
'follower' => $user,
'isActive' => true
));
$followingUsers = array();
foreach($following as $key => $follow) {
$followingUsers[] = $follow->getUser();
}
$query = $em->createQuery("
SELECT p
FROM AppBundle:Photo p
JOIN AppBundle:User u
WHERE p.user IN(:users)
AND p.isModerated = :isModerated
AND p.isActive = :isActive
ORDER BY p.creationDate DESC
")
->setParameters(array(
'users' => $followingUsers,
'isModerated' => true,
'isActive' => true
))
->setMaxResults(10);
$photos = $query->getResult();
首先我得到了关注用户,然后创建用户数组查询结果。然后我试图获取这些用户的照片,并限制查询结果。
我的查询结果只有3行,但实际上我有很多照片(超过10张)。
为什么限制并不适合我,问题是什么?