gpt4 book ai didi

mysql - 为什么此连接查询不能与 createQueryBuilder 一起使用?

转载 作者:行者123 更新时间:2023-11-29 13:25:27 29 4
gpt4 key购买 nike

这很好用

SELECT * FROM podcasttags
INNER JOIN podcast
ON podcasttags.podcastid = podcast.id
INNER JOIN tag
ON podcasttags.tagid = tag.id

但是当我尝试使用doctrine1 createQueryBuilder 时出现错误:

$queryBuilder = $this->db->createQueryBuilder()
->select('pt')
->from('podcasttags', 'pt')
->innerJoin('podcast p ON pt.podcastid = p.id')
->innerJoin('tag t ON pt.tagid = t.id');
$statement = $queryBuilder->execute();
$podcastData = $statement->fetchAll();

Warning: Missing argument 2 for Doctrine\DBAL\Query\QueryBuilder::innerJoin(), called in C:\xampp\htdocs\FDRPodcast\src\FDRPodcast\Repository\PodcastRepository.php on line 49 and defined in C:\xampp\htdocs\FDRPodcast\vendor\doctrine\dbal\lib\Doctrine\DBAL\Query\QueryBuilder.php on line 601

Warning: Missing argument 3 for Doctrine\DBAL\Query\QueryBuilder::innerJoin(), called in C:\xampp\htdocs\FDRPodcast\src\FDRPodcast\Repository\PodcastRepository.php on line 49 and defined in C:\xampp\htdocs\FDRPodcast\vendor\doctrine\dbal\lib\Doctrine\DBAL\Query\QueryBuilder.php on line 601

Notice: Undefined variable: join in C:\xampp\htdocs\FDRPodcast\vendor\doctrine\dbal\lib\Doctrine\DBAL\Query\QueryBuilder.php on line 606

Notice: Undefined variable: alias in C:\xampp\htdocs\FDRPodcast\vendor\doctrine\dbal\lib\Doctrine\DBAL\Query\QueryBuilder.php on line 607

Warning: Missing argument 2 for Doctrine\DBAL\Query\QueryBuilder::innerJoin(), called in C:\xampp\htdocs\FDRPodcast\src\FDRPodcast\Repository\PodcastRepository.php on line 50 and defined in C:\xampp\htdocs\FDRPodcast\vendor\doctrine\dbal\lib\Doctrine\DBAL\Query\QueryBuilder.php on line 601

Warning: Missing argument 3 for Doctrine\DBAL\Query\QueryBuilder::innerJoin(), called in C:\xampp\htdocs\FDRPodcast\src\FDRPodcast\Repository\PodcastRepository.php on line 50 and defined in C:\xampp\htdocs\FDRPodcast\vendor\doctrine\dbal\lib\Doctrine\DBAL\Query\QueryBuilder.php on line 601

最佳答案

Doctrine 手册中的示例:

$q = Doctrine_Query::create()
->select('u.id')
->from('User u')
->leftJoin('u.Groups g')
->innerJoin('u.Phonenumbers p')
->leftJoin('u.Email e');

所以你的查询应该是这样的:

$queryBuilder = $this->db->createQueryBuilder()
->select('pt')
->from('podcasttags pt')
->innerJoin('pt.podcast p')
->innerJoin('pt.tag t');

它接着说像“pt.tagid = t.id”这样的东西是不必要的,因为 Doctrine 默认情况下会关联主键。希望这会有所帮助。

关于mysql - 为什么此连接查询不能与 createQueryBuilder 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20201408/

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