Bonjour ,
j'utilise symfony4 et API platform . Je travaille sur le developpement d'une api restful . J'ai 2 entités qui me posent un soucis `Category` et `Tags` . Pour insérer des données dans la table Category je pensais pouvoir le faire avec ce format :
mais l'interface web de API PLATEFORM me présente ce format :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 { "id": 0, "name": "string", "cover": "string" }
or moi je souhaite supprimer "tags" et insérer directement dans la table Category .
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 { "id": 0, "name": "string", "tags": [ { "id": 0, "title": "string" } ], "cover": "string" }
Mes entités :
and Tag.php :
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
40
41
42 /** * @ApiResource( * normalizationContext={"groups"={"Category_read"}}, * denormalizationContext={"groups"={"Category_write"}} * ) * @ORM\Entity(repositoryClass=CategoryRepository::class) * @ApiFilter(SearchFilter::class, properties={"name": "partial"}) */ class Category { /** * @ORM\Id() * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") * @Groups({"Category_read","Category_write","Tag_read"}) */ private $id; /** * @ORM\Column(type="string", length=255) * @Groups({"Category_read","Category_write","Tag_read"}) */ private $name; /** * @ORM\ManyToMany(targetEntity=Tag::class, inversedBy="categories") * @Groups({"Category_read","Category_write"}) */ private $tags; /** * @ORM\Column(type="string", length=255, nullable=true) * @Groups({"Category_read","Category_write"}) */ private $cover; public function __construct() { $this->tags = new ArrayCollection(); } ... }
Merci d'avance pour votre aide
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 /** * @ORM\Entity(repositoryClass="App\Repository\TagRepository") * @ApiResource( * normalizationContext={"groups"={"Tag_read"}}, * denormalizationContext={"groups"={"Tag_write"}} * ) * @ApiFilter(SearchFilter::class, properties={"title": "start"}) */ class Tag { /** * @ORM\Id() * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") * @Groups({"Category_read","Tag_read"}) */ private $id; /** * @ORM\Column(type="string", length=255) * @Groups({"Category_read","Tag_read"}) */ private $title; /** * @ORM\ManyToMany(targetEntity=Category::class, mappedBy="tags") * @Groups({"Tag_read"}) */ private $categories; public function __construct() { $this->categories = new ArrayCollection(); } }
Partager