Boa tarde. Tive o seguinte erro:
Meu arquivo list-students.php:
<?php
use Alura\Doctrine\Entity\Course;
use Alura\Doctrine\Entity\Phone;
use Alura\Doctrine\Entity\Student;
use Alura\Doctrine\Helper\EntityManagerCreator;
require_once __DIR__ . '/../vendor/autoload.php';
$entityManager = EntityManagerCreator::createEntityManager();
$dql = "SELECT student FROM Alura\\Doctrine\\Entity\\Student student";
$studentList = $entityManager->createQuery($dql)->getResult();
foreach ($studentList as $student) {
echo "ID: $student->id\nNome: $student->name";
if ($student->phones()->count() > 0) {
echo PHP_EOL;
echo "Telefones: ";
echo implode(', ', $student->phones()
->map(fn(Phone $phone) => $phone->number)
->toArray());
}
if ($student->courses()->count() > 0) {
echo PHP_EOL;
echo "Cursos: ";
echo implode(', ', $student->courses()
->map(fn(Course $course) => $course->nome)
->toArray());
}
echo PHP_EOL . PHP_EOL;
}
$studentClass = Student::class;
$dql2 = "SELECT COUNT(student) FROM $studentClass student";
var_dump($entityManager->createQuery($dql)->getSingleScalarResult());