Bonjour à tous,

Merci d'avance pour votre aide.

J'ai une entity "TargetGroup" qui contient 2 relations OneToMany Bidirectionnelle, "Creatives" et "CreativesCard" (ce sont des ArrayCollection de respectivement l'entitée "Creative" et l'entitée "CreativeCard".

Au submit, j'ai bien une "Creative" qui s'enregistre avec un "TargetGroup Id". Je peux en ajouter, supprimer ou les modifier sans problème.
Cependant, la ou les "CreativeCard" ne récupèrent pas de "TargetGroup Id" et donc ne persistent pas en base.

Voici l'entitée "TargetGroup" :
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php/**
 * TargetGroup
 *
 * @ORM\Table(name="twitter_target_group")
 * @ORM\Entity
 */
class TargetGroup
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
 
    /**
     * @var ArrayCollection
     *
     * @ORM\OneToMany(targetEntity="Creative", mappedBy="targetGroup", cascade={"persist"}, orphanRemoval=true)
     */
    private $creatives;
 
    /**
     * @var ArrayCollection
     *
     * @ORM\OneToMany(targetEntity="CreativeCard", mappedBy="targetGroup", cascade={"persist"}, orphanRemoval=true)
     */
    private $creativesCard;
 
    public function __construct()
    {
        $this->creatives = new ArrayCollection();
        $this->creativesCard = new ArrayCollection();
    }
 
    public function addCreative(Creative $creative)
    {
        $this->creatives->add($creative);
        $creative->setTargetGroup($this);
    }
 
    public function removeCreative(Creative $creative)
    {
        $this->creatives->removeElement($creative);
        $creative->setTargetGroup(null);
    }
 
    public function getCreatives()
    {
        return $this->creatives;
    }
 
    /**
     * @param ArrayCollection $creatives
     */
    public function setCreatives($creatives)
    {
        $this->creatives = $creatives;
    }
 
    public function addCreativeCard(CreativeCard $creativeCard)
    {
        $this->creativesCard->add($creativeCard);
        $creativeCard->setTargetGroup($this);
    }
 
    public function removeCreativeCard(CreativeCard $creativeCard)
    {
        $this->creativesCard->removeElement($creativeCard);
        $creativeCard->setTargetGroup(null);
    }
 
    public function getCreativesCard()
    {
        return $this->creativesCard;
    }
 
    /**
     * @param ArrayCollection $creativesCard
     */
    public function setCreativesCard($creativesCard)
    {
        $this->creativesCard = $creativesCard;
    }
 
}
Et voici les deux entités "Creative" et "CreativeCard" :
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
43
44
45
46
47
48
<?php/**
 * CreativeCard
 *
 * @ORM\Table(name="twitter_creative_card")
 * @ORM\Entity
 */
class CreativeCard
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
 
    /**
     * @var stdClass
     * @ORM\ManyToOne(targetEntity="TargetGroup", inversedBy="creativesCard")
     */
    private $targetGroup;
 
    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }
 
    /**
     * @return stdClass
     */
    public function getTargetGroup()
    {
        return $this->targetGroup;
    }
 
    /**
     * @param stdClass $targetGroup
     */
    public function setTargetGroup($targetGroup)
    {
        $this->targetGroup = $targetGroup;
    }
 
}
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
43
44
45
46
47
48
<?php/**
 * Creative
 *
 * @ORM\Table(name="twitter_creative")
 * @ORM\Entity
 */
class Creative
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
 
    /**
     * @var stdClass
     * @ORM\ManyToOne(targetEntity="TargetGroup", inversedBy="creatives")
     */
    private $targetGroup;
 
    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }
 
    /**
     * @return stdClass
     */
    public function getTargetGroup()
    {
        return $this->targetGroup;
    }
 
    /**
     * @param stdClass $targetGroup
     */
    public function setTargetGroup($targetGroup)
    {
        $this->targetGroup = $targetGroup;
    }
 
}
Et enfin le code du submit, allégé pour pas m'étaler sur 3 pages (arborescence de $campaign = $campaign->Collection de $target-> Collection de $targetGroup-> Collection de $creative + Collection de $creativeCard et tout est en cascade persist) :
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
<?php
public function targetSubmitAction()
{
    $campaign = $em->getRepository(Campaign::class)->find($id);
 
        if($request->getMethod() !== 'POST')
            return new JsonResponse("Les requêtes ". $request->getMethod() ." ne sont pas acceptées pour cet endpoint. Veuillez utiliser une requête POST",405);
 
        if(empty($campaign))
            return new JsonResponse("La campagne n'existe pas",404);
 
        if(!in_array($channel,array_merge($campaign->getActiveChannels(),['config'])))
            return new JsonResponse("Le canal \"". htmlspecialchars($channel) ."\" n'existe pas (ou n'est pas activé pour cette campagne)",404);
 
        $activeChannelsInfos = array_merge(Channels::CHANNELS,Channels::TARGETS_CONFIG_AS_A_CHANNEL);
 
        $channelInfo = $activeChannelsInfos[$channel];
 
        $form = $this->createForm($channelInfo["targetsForm"], $campaign);
 
        $form->handleRequest($request);
 
        if ($form->isSubmitted() && $form->isValid())
        {
            $em->persist($campaign);
            $em->flush();
 
            return new JsonResponse();
        }
 
}
Pour information, j'ai d'autres entity qui fonctionnent de la même façon, j'ai essayé de repartir de ça mais rien n'y fait. Je viens d'arriver dans la société et je reprend du code existant en intégrant le mien donc pas facile de s'y retrouver.

Si jamais quelqu'un peut m'aider ce serait top.

Bonne soirée à tous