Hello,

J'ai deux entité avec une relation ManyToOne bidirectionnelle c'est à dire que dans :
Mon entité Honoraire j'ai :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
	/**
	 * @ORM\ManyToOne(targetEntity="Nas\AppBundle\Entity\Specialite", inversedBy="honoraires")
	 * @ORM\JoinColumn(nullable=false)
	 */
	private $specialite;
Et dans mon entité Specialite j'ai :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
 
	/**
	* @ORM\OneToMany(targetEntity="Nas\AppBundle\Entity\Honoraire", mappedBy="specialite", cascade={"persist"})
	*/
	private $honoraires; // Ici honoraires prend un « s », car une spécialité a plusieurs honoraires !
Ceci afin de faire un formulaire pour créer des spécialité et en même temps créer les honoraires qui vont bien. Dans mon formulaire "Specialite" je peux ajouter (imbriquer) x nombre de formulaire "Honoraire".
Mais quand je valide mon formulaire j'ai une erreur :
An exception occurred while executing 'INSERT INTO Honoraire (type, pourcentageFacture, pourcentageDevis, specialite_id) VALUES (?, ?, ?, ?)' with params ["tre", "123", null, null]:
Je ne vois pas comment régler le problème... Besoin d'aide

Je post le code de mon entité "Spécialite" afin de montrer comment je gère la relation avec la collection d'honoraire :
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
<?php
 
namespace Nas\AppBundle\Entity;
 
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
 
/**
 * Specialite
 *
 * @ORM\Table(name="specialite")
 * @ORM\Entity(repositoryClass="Nas\AppBundle\Entity\SpecialiteRepository")
 * @UniqueEntity (fields="specialite", message="Cette specialite existe deja.")
 */
class Specialite
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
 
    /**
     * @var string
     *
     * @ORM\Column(name="specialite", type="string", length=255)
     */
    private $specialite;
 
	/**
	* @ORM\OneToMany(targetEntity="Nas\AppBundle\Entity\Honoraire", mappedBy="specialite", cascade={"persist"})
	*/
	private $honoraires; // Ici honoraires prend un « s », car une spécialité a plusieurs honoraires !
 
    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
 
    /**
     * Set specialite
     *
     * @param string $specialite
     * @return Specialite
     */
    public function setSpecialite($specialite)
    {
        $this->specialite = $specialite;
 
        return $this;
    }
 
    /**
     * Get specialite
     *
     * @return string 
     */
    public function getSpecialite()
    {
        return $this->specialite;
    }
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->honoraires = new \Doctrine\Common\Collections\ArrayCollection();
    }
 
    /**
     * Add honoraires
     *
     * @param \Nas\AppBundle\Entity\Honoraire $honoraires
     * @return Specialite
     */
    public function addHonoraire(\Nas\AppBundle\Entity\Honoraire $honoraire)
    {		
        $this->honoraires[] = $honoraire;
		$honoraires->setSpecialite($this);
 
        return $this;
    }
 
    /**
     * Remove honoraires
     *
     * @param \Nas\AppBundle\Entity\Honoraire $honoraires
     */
    public function removeHonoraire(\Nas\AppBundle\Entity\Honoraire $honoraire)
    {
        $this->honoraires->removeElement($honoraires);
    }
 
    /**
     * Get honoraires
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getHonoraires()
    {
        return $this->honoraires;
    }
}
Merci pour votre aide

Ju