fiz como na aula e coloquei o
<?php
namespace Alura\Doctrine\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
/**
* @Entity(repositoryClass="Alura\Doctrine\Repository\AlunoRepository")
*/
class Aluno
{
/**
* @Id
* @GeneratedValue
* @Column(type="integer")
*/
private int $id;
/**
* @Column(type="string")
*/
private string $nome;
/**
* @OneToMany(targetEntity="Telefone", mappedBy="aluno", cascade={"remove", "persist"})
*/
private $telefones;
/**
* @ManyToMany(targetEntity="Curso", mappedBy="alunos")
*/
private $cursos;
na class Aluno e mesmo assim no arquivo relatorio-cursos-aluno-repository.php
<?php
use Alura\Doctrine\Entity\Aluno;
use Alura\Doctrine\Entity\Telefone;
use Alura\Doctrine\Helper\EntityManagerFactory;
use Doctrine\DBAL\Logging\DebugStack;
require_once __DIR__ . '/../vendor/autoload.php';
$entityManagerFactory = new EntityManagerFactory();
$entityManager = $entityManagerFactory -> getEntityManager();
$alunosRepository = $entityManager->getRepository(Aluno::class);
$debugStack = new DebugStack();
$entityManager->getConfiguration()->setSQLLogger($debugStack);
/**@var Aluno[] $alunos */
$alunos = $alunosRepository->buscaCursosPorAluno();
o buscaCursosPorAluno(); fica marcado como erro Undefined method 'buscaCursosPorAluno . intelephense(1013) e quando tento rodar aparece isso
PS C:\Users\luize\OneDrive\Documentos\alura\doctrine\commands> php relatorio-cursos-aluno-repository.php
PHP Fatal error: Uncaught Doctrine\ORM\Query\QueryException: SELECT aluno, telefones, cursos FROM Alura\Doctrine\Repository\Aluno aluno JOIN aluno.telefones telefones JOIN aluno.cursos cursos in C:\Users\luize\OneDrive\Documentos\alura\doctrine\vendor\doctrine\orm\lib\Doctrine\ORM\Query\QueryException.php:43
Stack trace:
#0 C:\Users\luize\OneDrive\Documentos\alura\doctrine\vendor\doctrine\orm\lib\Doctrine\ORM\Query\Parser.php(506): Doctrine\ORM\Query\QueryException::dqlError('SELECT aluno, t...')
#1 C:\Users\luize\OneDrive\Documentos\alura\doctrine\vendor\doctrine\orm\lib\Doctrine\ORM\Query\Parser.php(1004): Doctrine\ORM\Query\Parser->semanticalError('line
0, col 37 ...', Array)
#2 C:\Users\luize\OneDrive\Documentos\alura\doctrine\vendor\doctrine\orm\lib\Doctrine\ORM\Query\Parser.php(1750): Doctrine\ORM\Query\Parser->validateAbstractSchemaName('Alura\\Doctrine\\...')
#3 C:\Users\luize\OneDrive\Documentos\alura\doctrine\vendor\doctrine\orm\lib\Doctrine\ORM\Query\Parser.php(1601): Doctrine\ORM\Query\Parser->RangeVariableDeclara in C:\Users\luize\OneDrive\Documentos\alura\doctrine\vendor\doctrine\orm\lib\Doctrine\ORM\Query\QueryException.php on line 65
Fatal error: Uncaught Doctrine\ORM\Query\QueryException: SELECT aluno, telefones, cursos FROM Alura\Doctrine\Repository\Aluno aluno JOIN aluno.telefones telefones JOIN aluno.cursos cursos in C:\Users\luize\OneDrive\Documentos\alura\doctrine\vendor\doctrine\orm\lib\Doctrine\ORM\Query\QueryException.php:43
Stack trace:
#0 C:\Users\luize\OneDrive\Documentos\alura\doctrine\vendor\doctrine\orm\lib\Doctrine\ORM\Query\Parser.php(506): Doctrine\ORM\Query\QueryException::dqlError('SELECT aluno, t...')
#1 C:\Users\luize\OneDrive\Documentos\alura\doctrine\vendor\doctrine\orm\lib\Doctrine\ORM\Query\Parser.php(1004): Doctrine\ORM\Query\Parser->semanticalError('line 0, col 37 ...', Array)
#2 C:\Users\luize\OneDrive\Documentos\alura\doctrine\vendor\doctrine\orm\lib\Doctrine\ORM\Query\Parser.php(1750): Doctrine\ORM\Query\Parser->validateAbstractSchemaName('Alura\\Doctrine\\...')
#3 C:\Users\luize\OneDrive\Documentos\alura\doctrine\vendor\doctrine\orm\lib\Doctrine\ORM\Query\Parser.php(1601): Doctrine\ORM\Query\Parser->RangeVariableDeclara in C:\Users\luize\OneDrive\Documentos\alura\doctrine\vendor\doctrine\orm\lib\Doctrine\ORM\Query\QueryException.php on line 65
arquivo AlunoRepository.php esta assim
<?php
namespace Alura\Doctrine\Repository;
use Alura\Doctrine\Entity\Telefone;
use Doctrine\ORM\EntityRepository;
class AlunoRepository extends EntityRepository
{
public function buscaCursosPorAluno()
{
$query = $this->createQueryBuilder('aluno')
->join('aluno.Telefone', 'telefone')
->join('aluno.cursos', 'cursos')
->addSelect('telefone')
->addSelect('cursos')
->getQuery();
return $query->getResult();
}
}