gpt4 book ai didi

php - Symfony2 - 通知 : Undefined offset: 0 due to a custom Query

转载 作者:可可西里 更新时间:2023-10-31 22:45:50 25 4
gpt4 key购买 nike

我有这个错误:

"Notice: Undefined offset: 0 in C:\wamp\www\Videotheque\vendor\doctrine\lib\Doctrine\ORM\QueryBuilder.php line 240"

我正在创建一个在线视频集。有 2 个实体:电影和流派。在我的 GenRepository 方法中,我尝试将函数 findAll() 重新定义为与某个流派相关联的电影数量。

这是函数:

public function myFindAll()
{
$genres = $this->_em->createQueryBuilder('g')
// leftJoin because I need all the genre
->leftJoin('g.films', 'f')
->addSelect('COUNT(f)')
->groupBy('g')
->getQuery()
->getArrayResult();
// $genres contains all the genres and the associated movies
return ($genres);
}

最佳答案

Repository 类提供了创建已为实体配置的 QueryBuilder 的方法,因此我们可以直接放置:

$this->createQueryBuilder('g')

关于php - Symfony2 - 通知 : Undefined offset: 0 due to a custom Query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11755942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com