只需要加入第一个上传到他的画廊图片的会员,但有一个大问题,因为我是 symfony 的新手。
表:
CREATE TABLE `member` (
`member_id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`member_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `image` (
`image_id` int(10) NOT NULL AUTO_INCREMENT,
`member_id` int(10) NOT NULL,
`path` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`image_id`),
KEY `image_member_id_idx` (`member_id`),
CONSTRAINT `image_member_id` FOREIGN KEY (`member_id`) REFERENCES `member` (`member_id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
行动:
$items = $this->getDoctrine()
->getManager()
->getRepository('AcmeMyBundle:Member')
->createQueryBuilder('m')
->select('m','i')
->leftJoin('Acme\MyBundle\Entity\Image', 'i', 'WITH','i.memberId = m.memberId')
->addGroupBy('m.memberId')
->setMaxResults(10)
->getQuery()
->getArrayResult();
它返回 2 倍于数据库中的记录,而不是在我打印->getQuery->getSQL()
时返回的限制和分组设置
SELECT m0_.member_id AS member_id0,
m0_.name AS name1,
i1_.image_id AS image_id2,
i1_.path AS path3,
i1_.member_id AS member_id4
FROM member m0_
LEFT JOIN image i1_
ON (i1_.member_id = m0_.member_id)
GROUP BY m0_.member_id LIMIT 10
并且此查询在直接从数据库执行时返回正确答案。我需要帮助哪里可能出错?