Bonjour,
J'ai une table People qui à un lien 1-n vers etudiants, je voudrais donc retourner toutes les infos.
Actuellement j'obtiens ceci

Code json : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
  "hydra:member": [
        {
            "id_people": 1,
            "identifiant": "etu******",
            "nom": "********",
            "prenom": "Amandine",
            "matricule": *******,
            "hash": "795f28aaab5c7ac95c89ca32c5846aca",
            "uuid": "0308c5b7-747b-4b13-8588-001e3c9b2701",
            "numero": 2,
            "created_at": "2019-05-02",
            "updated_at": "2019-05-02",
            "id_etudiant": 1,
            "email_ad": "etu*****@student.henallux.be",
            "email_perso": "amandine.*****.02@student.henallux.be"
        },
        {
             "id_people": 1,
            "identifiant": "etu******",
            "nom": "********",
            "prenom": "Amandine",
            "matricule": *******,
            "hash": "795f28aaab5c7ac95c89ca32c5846aca",
            "uuid": "0308c5b7-747b-4b13-8588-001e3c9b2701",
            "numero": 2,
            "created_at": "2019-05-02",
            "updated_at": "2019-05-02",
            "id_etudiant": 2,
            "email_ad": "********@live.be",
            "email_perso": "amandine.********.02@student.henallux.be"
        },


Ce que je voudrais, quelque chose dans le genre :

Code json : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
 "hydra:member": [
        {
            "id_people": 1,
            "identifiant": "etu******",
            "nom": "********",
            "prenom": "Amandine",
            "matricule": *******,
            "hash": "795f28aaab5c7ac95c89ca32c5846aca",
            "uuid": "0308c5b7-747b-4b13-8588-001e3c9b2701",
            "numero": 2,
            "created_at": "2019-05-02",
            "updated_at": "2019-05-02",
             student {
              {
            "id_etudiant": 1,
            "email_ad": "etu*****@student.henallux.be",
            "email_perso": "amandine.*****.02@student.henallux.be"
 
             },
             {
            "id_etudiant": 2,
            "email_ad": "********@live.be",
            "email_perso": "amandine.********.02@student.henallux.be"
                   }
 
        },

Pour arriver à la première solution, je fais ceci, je suis sur que c'est pas la bonne solution :

Controller :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 
 
 
namespace App\Controller;
 
 
use App\Entity\Person;
use Doctrine\DBAL\Connection;
use Symfony\Component\Routing\Annotation\Route;
 
class Student
{
 
    /**
     * @param Person $data
     * @return Person
     * @Route(
     *     name="get_students",
     *     path="api/students",
     *     methods={"GET"},
     *     defaults={
     *       "_controller"="\App\Controller\Student::class",
     *       "_api_resource_class"="App\Entity\Person",
     *       "_api_collection_operation_name"="get_students"
     *     }
     *
     * )
     */
    public function __invoke(Connection $connection)
    {
        $sql = "select * 
                from brain.people p
                inner join brain.etudiants e
                on e.id_people = p.id_people";
        $data = $connection->fetchAll($sql);
        return $data;
    }
 
}
Entity :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
 
namespace App\Entity;
 
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
 
/**
 * Person
 * @ApiResource(
 *     itemOperations={
 *     "get",
 *     "get_students"={
 *         "method"="GET",
 *         "path"="api/students",
 *         "controller"=Student::class,
 *         "defaults"={"_api_receive"=false},
 *     }
 *     }
 *   )
 * @ORM\Table(schema="brain",name="people", indexes={@ORM\Index(name="IDX_1420BCB6F55AE19E", columns={"numero"})})
 * @ORM\Entity
 */
class Person
{
    /**
     * @var int
     * @Groups({"etudiant"})
     * @ORM\Column(name="id_people", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="SEQUENCE")
     * @ORM\SequenceGenerator(sequenceName="people_id_people_seq", allocationSize=1, initialValue=1)
     */
    private $idPeople;
......
Pouvez-vous me donner une piste ?

Merci.