Bonjour et merci d'avance à tous ceux et celles qui prendront la peine de m'aider!

Pour un projet de cour j'ai dû générer mes entity symfony3 depuis une base de données (et elle est pas tiptop malheureusement..).

Dans ma BdD j'ai ces 3 tables: "Users" OneToMany "Appeller" ManyToOne "Contact"
Appeller contient juste deux clés étrangères pour relié un User à tous ses contacts. De ces 3 tables j'ai généré 3 entity: Users, Contact et Appeller:
Users:

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
/**
 * Users
 *
 * @ORM\Table(name="users")
 * @ORM\Entity(repositoryClass="DCB\ApprentissagesBundle\Entity\UsersRepository")
 */
class Users {
    //comme l'entity classe fait environ 260 lignes j'ai enlevé tous les champs générés depuis la base de données (sauf l'id) pour vous laissé le minimum que vous avez besoin
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;
 
    public function setId($id) {
        $this->id = $id;
    }
 
    public function getId() {
        return $this->id;
    }
 
    /**
     * @ORM\OneToMany(targetEntity="DCB\ApprentissagesBundle\Entity\Contact",mappedBy="contact", cascade={"persist"})
     */
    private $contacts;
 
    public function addContacts($contact) {
        $this->contacts[] = $contact;
    }
 
    public function getContact() {
        return $this->contacts;
    }
 
    public function removeContact($contact) {
        $this->contacts->removeElement($contact);
    }
 
    public function __construct(){
        $this->contacts = new ArrayCollection();
    }
}


Contact (~130l)

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
/**
 * Contact
 *
 * @ORM\Table(name="contact")
 * @ORM\Entity
 */
class Contact {
 
    /**
     * @var integer
     *
     * @ORM\Column(name="id_contact", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $idContact;
 
    public function setIdContact($idContact) {
        $this->idContact = $idContact;
    }
 
    public function getIdContact() {
        return $this->idContact;
    }
 
    /**
     * @var string
     *
     * @ORM\Column(name="nom_contact", type="string", length=25, nullable=true)
     */
    private $nomContact;
 
    public function setNomContact($nomContact) {
        $this->nomContact = $nomContact;
    }
 
    public function getNomContact() {
        return $this->nomContact;
    }
 
    /**
     * @var string
     *
     * @ORM\Column(name="prenom_contact", type="string", length=25, nullable=true)
     */
    private $prenomContact;
 
    public function setPrenomContact($prenomContact) {
        $this->prenomContact = $prenomContact;
    }
 
    public function getPrenomContact() {
        return $this->prenomContact;
    }
 
    /**
     * @var string
     *
     * @ORM\Column(name="adrese_contact", type="string", length=100, nullable=true)
     */
    private $adreseContact;
 
    public function setAdreseContact($adreseContact) {
        $this->adreseContact = $adreseContact;
    }
 
    public function getAdreseContact() {
        return $this->adreseContact;
    }
 
    /**
     * @var string
     *
     * @ORM\Column(name="CP_contact", type="string", length=6, nullable=true)
     */
    private $cpContact;
 
    public function setCpContact($cpContact) {
        $this->cpContact = $cpContact;
    }
 
    public function getCpContact() {
        return $this->cpContact;
    }
 
    /**
     * @var string
     *
     * @ORM\Column(name="ville_contact", type="string", length=25, nullable=true)
     */
    private $villeContact;
 
    public function setVilleContact($villeContact) {
        $this->villeContact = $villeContact;
    }
 
    public function getVilleContact() {
        return $this->villeContact;
    }
 
    /**
     * @var string
     *
     * @ORM\Column(name="telFixe_contact", type="string", length=10, nullable=true)
     */
    private $telfixeContact;
 
    public function setTelfixeContact($telfixeContact) {
        $this->telfixeContact = $telfixeContact;
    }
 
    public function getTelfixeContact() {
        return $this->telfixeContact;
    }
 
    /**
     * @var string
     *
     * @ORM\Column(name="telMobile_contact", type="string", length=10, nullable=true)
     */
    private $telmobileContact;
 
    public function setTelmobileContact($telmobileContact) {
        $this->telmobileContact = $telmobileContact;
    }
 
    public function getTelmobileContact() {
        return $this->telmobileContact;
    }
 
}


Appeller

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
 
/**
 * Appeller
 *
 * @ORM\Table(name="appeller", indexes={@ORM\Index(name="FK_appeller_id_contact", columns={"id_contact"}), @ORM\Index(name="fk_appeller_users1_idx", columns={"users_id"})})
 * @ORM\Entity(repositoryClass="DCB\ApprentissagesBundle\Entity\AppellerRepository")
 */
class Appeller {
 
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;
 
    public function setId($id) {
        $this->id = $id;
    }
 
    public function getId() {
        return $this->id;
    }
 
    /**
     * @var \Contact
     *
     * @ORM\ManyToOne(targetEntity="Contact")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="id_contact", referencedColumnName="id_contact")
     * })
     */
    private $contact;
 
    public function setContact($contact) {
        $this->contact = $contact;
    }
 
    public function getContact() {
        return $this->contact;
    }
 
    /**
     * @var \Users
     *
     * @ORM\ManyToOne(targetEntity="Users")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="users_id", referencedColumnName="id")
     * })
     */
    private $users;
 
    public function setUsers($users) {
        $this->users = $users;
    }
 
    public function getUsers() {
        return $this->users;
    }
}



Pour créer et insérer un nouveau User et ses contacts dans la BdD j'ai 2 formulaires:
ContactType:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('nomContact', TextType::class)
                ->add('prenomContact', TextType::class)
                ->add('adreseContact', TextType::class)
                ->add('cpContact', TextType::class)
                ->add('villeContact', TextType::class)
                ->add('telfixeContact', TextType::class)
                ->add('telmobileContact', TextType::class);
    }



ContactType est utilisé en CollectionType::class dans UsersType:

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
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('name', TextType::class, array('label' => 'Nom:'))
                ->add('prenom', TextType::class, array('label' => 'Prénom:'))
                ->add('role', TextType::class)
                ->add('email', EmailType::class, array('label' => 'Email:'))
                ->add('password', PasswordType::class)
                ->add('createdAt', DateType::class)
                ->add('updatedAt', DateType::class)
                ->add('adresse', TextType::class, array('label' => 'Adresse:'))
                ->add('cp', TextType::class, array('label' => 'Code Postal:'))
                ->add('ville', TextType::class, array('label' => 'Ville:'))
                ->add('telephone', TextType::class, array('label' => 'Téléphone:'))
                ->add('dob', BirthdayType::class, array('label' => 'Date de naissance:'))
                ->add('contact', CollectionType::class, array(
                                                    'entry_type' => ContactType::class,
                                                    'allow_add' => TRUE,
                                                    'allow_delete' => TRUE
                                               )
                      )
                ->add('Enregistrer', SubmitType::class);
    }


En suivant un cours je suis arrivé a faire s'afficher le form Contact avec possibilité d'en ajouté un et d'en supprimé un (via le script JS du tuto que j'ai un peu modifier).

Mais j'ai encore 2 problèmes que je n'arrive pas à résoudre (j'ai cherché sur le web quand même ):
Lors de l'insertion dans la base, seulement le user et le dernier contact saisie est insérer.
De plus la table Appeller qui fait le lien entre un User et ses Contact n'est pas remplie...

Je précise
Je suis débutant sur symfony (1er projet!) quelqu'un pour m'aider??