Bonjour,
J'ai un problème que je n'arrive pas a résoudre.
J'ai un formulaire imbriqué, imbriquant 3 entités, Forfait, presta, et QuttprestaForfait qui est l'entité associative de Forfait et presta.
Je souhaite que QuttPrestaForfait ne puisse pas avoir 2 entrées où forfait_id et presta_id soit les meme j'ai donc créé une contrainte Uniqueentity sur ces deux champs.
Mais voila que lors de l'insertion il n'y a aucun problème ca passe quand meme, par contre lors de la deletion ca ne passe pas le validateur m'empeche de valider mon formulaire.

mon entité forfait:
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
 
namespace SB\PrestaBundle\Entity;
 
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
 
/**
 * Forfait
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="SB\PrestaBundle\Entity\ForfaitRepository")
 */
class Forfait
{
    /**
     * @ORM\OneToMany(targetEntity="SB\PrestaBundle\Entity\QuttPrestaForfait", mappedBy="forfait",cascade={"persist", "remove"})
     * @Assert\Valid()
     */
    private $quttprestaforfait;
 
    /**
     * @ORM\ManyToOne(targetEntity="SB\PrestaBundle\Entity\Prestacateg")
     * @ORM\JoinColumn(nullable=false)
     */
    private $prestacateg;
 
 
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
 
    /**
     * @var string
     *
     * @ORM\Column(name="title", type="string", length=255)
     */
    private $title;
 
    /**
     * @var string
     *
     * @ORM\Column(name="comment", type="text")
     */
    private $comment;
 
    /**
     * @var integer
     *
     * @ORM\Column(name="prix", type="integer")
     */
    private $prix;
 
    /**
     * @var boolean
     *
     * @ORM\Column(name="afficher", type="boolean")
     */
    private $afficher;
 
 
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->quttprestaforfait = new \Doctrine\Common\Collections\ArrayCollection();
    }
 
    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
 
    /**
     * Set title
     *
     * @param string $title
     * @return Forfait
     */
    public function setTitle($title)
    {
        $this->title = $title;
 
        return $this;
    }
 
    /**
     * Get title
     *
     * @return string 
     */
    public function getTitle()
    {
        return $this->title;
    }
 
    /**
     * Set comment
     *
     * @param string $comment
     * @return Forfait
     */
    public function setComment($comment)
    {
        $this->comment = $comment;
 
        return $this;
    }
 
    /**
     * Get comment
     *
     * @return string 
     */
    public function getComment()
    {
        return $this->comment;
    }
 
    /**
     * Set prix
     *
     * @param integer $prix
     * @return Forfait
     */
    public function setPrix($prix)
    {
        $this->prix = $prix;
 
        return $this;
    }
 
    /**
     * Get prix
     *
     * @return integer 
     */
    public function getPrix()
    {
        return $this->prix;
    }
 
    /**
     * Set afficher
     *
     * @param boolean $afficher
     * @return Forfait
     */
    public function setAfficher($afficher)
    {
        $this->afficher = $afficher;
 
        return $this;
    }
 
    /**
     * Get afficher
     *
     * @return boolean 
     */
    public function getAfficher()
    {
        return $this->afficher;
    }
 
 
    /**
     * Set prestacateg
     *
     * @param \SB\PrestaBundle\Entity\Prestacateg $prestacateg
     * @return Forfait
     */
    public function setPrestacateg(\SB\PrestaBundle\Entity\Prestacateg $prestacateg)
    {
        $this->prestacateg = $prestacateg;
 
        return $this;
    }
 
    /**
     * Get prestacateg
     *
     * @return \SB\PrestaBundle\Entity\Prestacateg 
     */
    public function getPrestacateg()
    {
        return $this->prestacateg;
    }
 
    /**
     * Add quttprestaforfait
     *
     * @param \SB\PrestaBundle\Entity\QuttPrestaForfait $quttprestaforfait
     * @return Forfait
     */
    public function addQuttprestaforfait(\SB\PrestaBundle\Entity\QuttPrestaForfait $quttprestaforfait)
    {
        $this->quttprestaforfait[] = $quttprestaforfait;
        $quttprestaforfait->setForfait($this);
        return $this;
    }
 
    /**
     * Remove quttprestaforfait
     *
     * @param \SB\PrestaBundle\Entity\QuttPrestaForfait $quttprestaforfait
     */
    public function removeQuttprestaforfait(\SB\PrestaBundle\Entity\QuttPrestaForfait $quttprestaforfait)
    {
        $this->quttprestaforfait->removeElement($quttprestaforfait);
    }
 
    /**
     * Get quttprestaforfait
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getQuttprestaforfait()
    {
        return $this->quttprestaforfait;
    }
}
Mon entité QuttPrestaForfait:
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
<?php
 
namespace SB\PrestaBundle\Entity;
 
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
 
/**
 * QuttPrestaForfait
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="SB\PrestaBundle\Entity\QuttPrestaForfaitRepository")
 * @UniqueEntity(fields={"forfait","presta"},message="Vous ne pouvez pas inserer 2 prestation semblable dans le meme forfait")
 */
class QuttPrestaForfait
{
    /**
     * @ORM\ManyToOne(targetEntity="SB\PrestaBundle\Entity\Forfait", inversedBy="quttprestaforfait")
     * @ORM\JoinColumn(name="forfait_id", nullable=false)
     */
    private $forfait;
 
    /**
     * @ORM\ManyToOne(targetEntity="SB\PrestaBundle\Entity\Presta", inversedBy="quttprestaforfait")
     * @ORM\JoinColumn(name="presta_id", nullable=false)
     */
    private $presta;
 
 
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
 
    /**
     * @var integer
     *
     * @ORM\Column(name="qutt", type="integer")
     */
    private $qutt;
 
 
    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
 
    /**
     * Set qutt
     *
     * @param integer $qutt
     * @return QuttPrestaForfait
     */
    public function setQutt($qutt)
    {
        $this->qutt = $qutt;
 
        return $this;
    }
 
    /**
     * Get qutt
     *
     * @return integer 
     */
    public function getQutt()
    {
        return $this->qutt;
    }
 
    /**
     * Set presta
     *
     * @param \SB\PrestaBundle\Entity\Presta $presta
     * @return QuttPrestaForfait
     */
    public function setPresta(\SB\PrestaBundle\Entity\Presta $presta = null)
    {
        $this->presta = $presta;
 
        return $this;
    }
 
    /**
     * Get presta
     *
     * @return \SB\PrestaBundle\Entity\Presta 
     */
    public function getPresta()
    {
        return $this->presta;
    }
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->presta = new \Doctrine\Common\Collections\ArrayCollection();
        $this->forfait = new \Doctrine\Common\Collections\ArrayCollection();
    }
 
    /**
     * Set forfait
     *
     * @param \SB\PrestaBundle\Entity\Forfait $forfait
     * @return QuttPrestaForfait
     */
    public function setForfait(\SB\PrestaBundle\Entity\Forfait $forfait = null)
    {
        $this->forfait = $forfait;
 
        return $this;
    }
 
    /**
     * Get forfait
     *
     * @return \SB\PrestaBundle\Entity\Forfait 
     */
    public function getForfait()
    {
        return $this->forfait;
    }
}
mon controleur:
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
<?php
 
    public function newAction()
    {
        $forfait = new Forfait();
        $form = $this->createForm('forfaittype', $forfait);
 
        $request = $this->get('request');
        if ($request->getMethod() == 'POST') {
          $form->bind($request);
          if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($forfait);
            $em->flush();
            $this->get('session')->getFlashBag()->add('info', 'forfait');
            return $this->redirect($this->generateUrl('presta_admin_all_forfait'));
            }
          }
        return $this->render('SBPrestaBundle:ForfaitAdmin:newforfait.html.twig', array('form' => $form->createView()));
    }
    public function supprAction($id)
    {
        $repository = $this->getDoctrine()
                           ->getManager()
                           ->getRepository('SBPrestaBundle:Forfait');
        $forfait = $repository->find($id);
        $form = $this->createForm(new ForfaitSupprType, $forfait);
        $request = $this->get('request');
        if ($request->getMethod() == 'POST') {
          $form->bind($request);
          if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->remove($forfait);
            $em->flush();
            $this->get('session')->getFlashBag()->add('info', 'forfait bien supprimée');
            return $this->redirect($this->generateUrl('presta_admin_all_forfait'));
            }
          }
        return $this->render('SBPrestaBundle:ForfaitAdmin:supprforfait.html.twig', array('id' => $forfait->getId(),'form' => $form->createView(),'forfait'=>$forfait));
    }