Je suis vraiment bloqué sur un problème depuis un bon bout de temps donc ça serait vraiment sympa de m'aider.
Voici l'énoncé du problème :
Deux entité :
- Categorie (les différentes catégories dans l'application)
- Mailing (le mailing de chaque catégorie - un simple texte)
Les deux entités sont en relation OneToOne bidirectionnelle.
Le problème :
Lorsqu'on créé une catégorie celle-ci est persistée sans problème mais le Mailing, qui doit être normalement cascadé, n'est pas persisté.
Dans la base, la table categorie le mailing_id de la catégorie qu'on vient de créer est = NULL
Un indice peut-être :
Si je créé le mailing "à la main" dans la base, par exemple :
dans la table catégorie : id = 15, .... mailing_id = 30
dans la table mailing : id = 30, texte = 'test'
=> Tout fonctionne normalement dans l'application, j'arrive à accéder au mailing de la catégorie ... etc ...
=> C'est vraiment la création qui pose problème
Le code :
Categorie :
Mailing :
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157 <?php namespace Asset\ReportManagerBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Table() * @ORM\Entity(repositoryClass="Asset\ReportManagerBundle\Entity\CategorieRepository") * @ORM\HasLifecycleCallbacks */ class Categorie { /** * @var integer $id * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string $nom * * @ORM\Column(name="nom", type="string", length=255) */ private $nom; /** * @ORM\ManyToOne(targetEntity="Asset\ReportManagerBundle\Entity\Operation", inversedBy="categories") * @ORM\JoinColumn(nullable=false) */ private $operation; /** * @ORM\OneToMany(targetEntity="Asset\ReportManagerBundle\Entity\Fichier", mappedBy="categorie", cascade={"persist", "remove"}) */ private $fichiers; private $nombreFichiersAjoutes; /** * @ORM\OneToOne(targetEntity="Asset\ReportManagerBundle\Entity\Mailing", inversedBy="categorie", cascade={"persist", "remove"}) */ private $mailing; public function __construct() { $this->fichiers = new \Doctrine\Common\Collections\ArrayCollection(); } public function getNombreFichiersAjoutes() { return $this->nombreFichiersAjoutes; } /** * @return integer */ public function getId() { return $this->id; } /** * @param string $nom * @return Categorie */ public function setNom($nom) { $this->nom = $nom; return $this; } /** * @return string */ public function getNom() { return $this->nom; } /** * Set operation * * @param \Asset\ReportManagerBundle\Entity\Operation $operation * @return Categorie */ public function setOperation(\Asset\ReportManagerBundle\Entity\Operation $operation) { $this->operation = $operation; return $this; } /** * Get operation * * @return \Asset\ReportManagerBundle\Entity\Operation */ public function getOperation() { return $this->operation; } /** * Add fichiers * * @param \Asset\ReportManagerBundle\Entity\Fichier $fichiers * @return Categorie */ public function addFichier(\Asset\ReportManagerBundle\Entity\Fichier $fichiers) { $this->fichiers[] = $fichiers; $fichiers->setCategorie($this); $this->nombreFichiersAjoutes++; return $this; } /** * Remove fichiers * * @param \Asset\ReportManagerBundle\Entity\Fichier $fichiers */ public function removeFichier(\Asset\ReportManagerBundle\Entity\Fichier $fichiers) { $this->fichiers->removeElement($fichiers); } /** * Get fichiers * * @return \Doctrine\Common\Collections\Collection */ public function getFichiers() { return $this->fichiers; } /** * @param string $mailing * @return Categorie */ public function setMailing(\Asset\ReportManagerBundle\Entity\Mailing $mailing) { $this->mailing = $mailing; return $this; } /** * @return string */ public function getMailing() { return $this->mailing; } }
Merci de 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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127 <?php namespace Asset\ReportManagerBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Table() * @ORM\Entity(repositoryClass="Asset\ReportManagerBundle\Entity\MailingRepository") * @ORM\HasLifecycleCallbacks() */ class Mailing { /** * @var integer $id * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string $texte * * @ORM\Column(name="texte", type="text", length=10000) */ private $texte; /** * @ORM\OneToOne(targetEntity="Asset\ReportManagerBundle\Entity\Categorie", mappedBy="mailing") */ private $categorie; /** * @ORM\ManyToMany(targetEntity="Asset\UserBundle\Entity\User", inversedBy="mailings", cascade={"persist"}) */ private $users; public function __construct() { $this->users = new \Doctrine\Common\Collections\ArrayCollection(); } /** * @return integer */ public function getId() { return $this->id; } /** * @param string $nom * @return Categorie */ public function setTexte($texte) { $this->texte = $texte; return $this; } /** * @return string */ public function getTexte() { return $this->texte; } /** * Add users * * * @param Asset\UserBundle\Entity\User $users */ public function addUser(\Asset\UserBundle\Entity\User $users) { $this->users[] = $users; $users->addOperation($this); return $this; } /** * Remove users * * @param Asset\UserBundle\Entity\User $users */ public function removeUser(\Asset\UserBundle\Entity\User $users) { $this->users->removeElement($users); $users->removeOperation($this); } /** * Get users * * @return Doctrine\Common\Collections\Collection */ public function getUsers() // Notez le « s », on récupère une liste de catégories ici ! { return $this->users; } /** * Set categorie * * @param \Asset\ReportManagerBundle\Entity\Categorie $categorie * @return Mailing */ public function setCategorie(\Asset\ReportManagerBundle\Entity\Categorie $categorie = null) { $this->categorie = $categorie; $categorie->setMailing($this); return $this; } /** * Get categorie * * @return \Asset\ReportManagerBundle\Entity\Categorie */ public function getCategorie() { return $this->categorie; } }
Partager