IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Doctrine2 PHP Discussion :

Problème avec une relation many-to-many


Sujet :

Doctrine2 PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Août 2002
    Messages
    94
    Détails du profil
    Informations forums :
    Inscription : Août 2002
    Messages : 94
    Par défaut Problème avec une relation many-to-many
    Voici le message d'erreur que j'ai lorsque j'essai d'accéder à ma page.

    "[Semantical Error] The annotation "@JoinTable" in property Ecole\InfoBundle\Entity\Enfant::$interventions was never imported. Did you maybe forget to add a "use" statement for this annotation?"

    Le code de mon entity enfant

    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
    <?php
     
    namespace Ecole\InfoBundle\Entity;
     
    use Doctrine\ORM\Mapping as ORM;
     
    /**
     * Ecole\InfoBundle\Entity\Enfant
     *
     * @ORM\Table()
     * @ORM\Entity(repositoryClass="Ecole\InfoBundle\Entity\EnfantRepository")
     */
    class Enfant
    {
        /**
         * @var integer $id
         *
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        private $id;
     
        /**
         * @var string $prenom
         *
         * @ORM\Column(name="prenom", type="string", length=255)
         */
        private $prenom;
     
        /**
         * @var string $nom
         *
         * @ORM\Column(name="nom", type="string", length=255)
         */
        private $nom;
     
        /**
         * @var date $dateNaissance
         *
         * @ORM\Column(name="dateNaissance", type="date")
         */
        private $dateNaissance;
     
        /**
         * @ORM\ManyToOne(targetEntity="Repondant",cascade={"persist"}) 
         */
        private $repondant;
        /**
         * @ORM\ManyToMany(targetEntity="Intervention",cascade={"persist"},inversedBy="enfants") 
         * 
         * 
         */
        private $interventions;
     
     
     
     
        /**
         * Get id
         *
         * @return integer 
         */
        public function getId()
        {
            return $this->id;
        }
     
        /**
         * Set prenom
         *
         * @param string $prenom
         */
        public function setPrenom($prenom)
        {
            $this->prenom = $prenom;
        }
     
        /**
         * Get prenom
         *
         * @return string 
         */
        public function getPrenom()
        {
            return $this->prenom;
        }
     
        /**
         * Set nom
         *
         * @param string $nom
         */
        public function setNom($nom)
        {
            $this->nom = $nom;
        }
     
        /**
         * Get nom
         *
         * @return string 
         */
        public function getNom()
        {
            return $this->nom;
        }
     
        /**
         * Set dateNaissance
         *
         * @param date $dateNaissance
         */
        public function setDateNaissance($dateNaissance)
        {
            $this->dateNaissance = $dateNaissance;
        }
     
        /**
         * Get dateNaissance
         *
         * @return date 
         */
        public function getDateNaissance()
        {
            return $this->dateNaissance;
        }
        public function getPrenomNom()
        {
            return $this->prenom. ' '.$this->getNom();
        }
     
     
     
     
        /**
         * Set repondant
         *
         * @param Ecole\InfoBundle\Entity\Repondant $repondant
         */
        public function setRepondant(\Ecole\InfoBundle\Entity\Repondant $repondant)
        {
            $this->repondant = $repondant;
        }
     
        /**
         * Get repondant
         *
         * @return Ecole\InfoBundle\Entity\Repondant 
         */
        public function getRepondant()
        {
            return $this->repondant;
        }
     
     
        public function __construct()
        {
            $this->interventions = new \Doctrine\Common\Collections\ArrayCollection();
        }
     
        /**
         * Add interventions
         *
         * @param Ecole\InfoBundle\Entity\Intervention $interventions
         */
        public function addIntervention(\Ecole\InfoBundle\Entity\Intervention $interventions)
        {
            $this->interventions[] = $interventions;
        }
     
        /**
         * Get interventions
         *
         * @return Doctrine\Common\Collections\Collection 
         */
        public function getInterventions()
        {
            return $this->interventions;
        }
    }
    Maintenant la page intervention
    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
    <?php
     
    namespace Ecole\InfoBundle\Entity;
     
    use Doctrine\ORM\Mapping as ORM;
     
    /**
     * Ecole\InfoBundle\Entity\Intervention
     *
     * @ORM\Table()
     * @ORM\Entity(repositoryClass="Ecole\InfoBundle\Entity\InterventionRepository")
     */
    class Intervention
    {
        /**
         * @var integer $id
         *
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        private $id;
     
        /**
         * @var string $raison
         *
         * @ORM\Column(name="raison", type="string", length=555)
         */
        private $raison;
     
        /**
         * @var string $commentaire
         *
         * @ORM\Column(name="commentaire", type="string", length=255)
         */
        private $commentaire;
     
        /**
         * @var date $date
         *
         * @ORM\Column(name="date", type="date")
         */
        private $date;
        /**
         * @ORM\ManyToMany(targetEntity="Enfant",cascade={"persist"}, mappedBy="enfants") 
         */
        private $enfants;
     
        /**
         * Get id
         *
         * @return integer 
         */
        public function getId()
        {
            return $this->id;
        }
     
        /**
         * Set raison
         *
         * @param string $raison
         */
        public function setRaison($raison)
        {
            $this->raison = $raison;
        }
     
        /**
         * Get raison
         *
         * @return string 
         */
        public function getRaison()
        {
            return $this->raison;
        }
     
        /**
         * Set commentaire
         *
         * @param string $commentaire
         */
        public function setCommentaire($commentaire)
        {
            $this->commentaire = $commentaire;
        }
     
        /**
         * Get commentaire
         *
         * @return string 
         */
        public function getCommentaire()
        {
            return $this->commentaire;
        }
     
        /**
         * Set date
         *
         * @param date $date
         */
        public function setDate($date)
        {
            $this->date = $date;
        }
     
        /**
         * Get date
         *
         * @return date 
         */
        public function getDate()
        {
            return $this->date;
        }
     
     
     
     
        public function __construct()
        {
            $this->enfants = new \Doctrine\Common\Collections\ArrayCollection();
        }
     
        /**
         * Add enfants
         *
         * @param Ecole\InfoBundle\Entity\Enfant $enfants
         */
        public function addEnfant(\Ecole\InfoBundle\Entity\Enfant $enfants)
        {
            $this->enfants[] = $enfants;
        }
     
        /**
         * Get enfants
         *
         * @return Doctrine\Common\Collections\Collection 
         */
        public function getEnfants()
        {
            return $this->enfants;
        }
    }
    Merci de votre aide

  2. #2
    Membre émérite

    Profil pro
    Inscrit en
    Juin 2004
    Messages
    772
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Juin 2004
    Messages : 772
    Par défaut
    Pour une relation ManyToMany, tu dois avoir une table d'association entre tes enfants et tes Interventions, du type :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    CREATE TABLE enfants_interventions (
        enfant_id INT NOT NULL,
        intervention_id INT NOT NULL,
        PRIMARY KEY(enfant_id, intervention_id)
    ) ENGINE = InnoDB;
    Et tu dois indiquer que c'est cette table qui fait le lien sur tes relations ManyToMany.

    Côté Enfant :
    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
    <?php
     
    namespace Ecole\InfoBundle\Entity;
     
    use Doctrine\ORM\Mapping as ORM;
     
    /**
     * Ecole\InfoBundle\Entity\Enfant
     *
     * @ORM\Table()
     * @ORM\Entity(repositoryClass="Ecole\InfoBundle\Entity\EnfantRepository")
     */
    class Enfant
    {
        // ....
     
        /**
         * @ORM\ManyToMany(targetEntity="Intervention",cascade={"persist"},inversedBy="enfants") 
         * @ORM\JoinTable(name="enfants_interventions",
         *      joinColumns={@ORM\JoinColumn(name="enfant_id", referencedColumnName="id")},
         *      inverseJoinColumns={@ORM\JoinColumn(name="intervention_id", referencedColumnName="id")}
         *      )
         */
        private $interventions;
     
        // ....

    Côté Intervention :
    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
    <?php
     
    namespace Ecole\InfoBundle\Entity;
     
    use Doctrine\ORM\Mapping as ORM;
     
    /**
     * Ecole\InfoBundle\Entity\Intervention
     *
     * @ORM\Table()
     * @ORM\Entity(repositoryClass="Ecole\InfoBundle\Entity\InterventionRepository")
     */
    class Intervention
    {
        // ....
     
        /**
         * @ORM\ManyToMany(targetEntity="Enfant",cascade={"persist"}, mappedBy="enfants") 
         * @ORM\JoinTable(name="enfants_interventions",
         *      joinColumns={@ORM\JoinColumn(name="intervention_id", referencedColumnName="id")},
         *      inverseJoinColumns={@ORM\JoinColumn(name="enfant_id", referencedColumnName="id")}
         *      )
         */
        private $enfants;
     
        // ....

  3. #3
    Membre confirmé
    Inscrit en
    Août 2002
    Messages
    94
    Détails du profil
    Informations forums :
    Inscription : Août 2002
    Messages : 94
    Par défaut Merci
    Merci pour ton temps mais malheureusement j'ai fait les modification mais le message d'erreur reste le même.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Neither property "enfant" nor method "getEnfant()" nor method "isEnfant()" exists in class "Ecole\InfoBundle\Entity\Intervention"

  4. #4
    Membre émérite

    Profil pro
    Inscrit en
    Juin 2004
    Messages
    772
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Juin 2004
    Messages : 772
    Par défaut
    D'où est lancée cette erreur ?

    Ne fais-tu pas un getEnfant() au lieu d'un getEnfants quelque part ? Dans un contrôleur ou un template Twig par exemple...

  5. #5
    Membre confirmé
    Inscrit en
    Août 2002
    Messages
    94
    Détails du profil
    Informations forums :
    Inscription : Août 2002
    Messages : 94
    Par défaut Re-bonjour
    Voici J'ai effacer mes fichiers créer avec le crud et recommencer. Tous mes dossiers ont été créer et j'ai maleheureusement le même problème. Par contre je me suis rendu compte que dans le dossier FORM il y avait de chamgement. Les voici.
    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
    <?php
     
    namespace Ecole\InfoBundle\Form;
     
    use Symfony\Component\Form\AbstractType;
    use Symfony\Component\Form\FormBuilder;
     
    class EnfantType extends AbstractType
    {
        public function buildForm(FormBuilder $builder, array $options)
        {
            $builder
                ->add('prenom')
                ->add('nom')
                ->add('dateNaissance')
                ->add('repondant',new RepondantType())
                ->add('interventions')
                    ;
        }
     
        public function getName()
        {
            return 'ecole_infobundle_enfanttype';
        }
    }
    et pour intervention

    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
    <?php
     
    namespace Ecole\InfoBundle\Form;
     
    use Symfony\Component\Form\AbstractType;
    use Symfony\Component\Form\FormBuilder;
     
    class InterventionType extends AbstractType
    {
        public function buildForm(FormBuilder $builder, array $options)
        {
            $builder
                ->add('raison')
                ->add('commentaire')
                ->add('date')
                ->add('enfants') ;
        }
     
        public function getName()
        {
            return 'ecole_infobundle_interventiontype';
        }
    }
    Merci encore

  6. #6
    Membre émérite

    Profil pro
    Inscrit en
    Juin 2004
    Messages
    772
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Juin 2004
    Messages : 772
    Par défaut
    Il faut que tu montres le log complet de l'erreur en question (fichier d'origine, ligne, stacktrace)

Discussions similaires

  1. Comment récupérer une liste avec une relation one to many ?
    Par tomlaurent dans le forum Hibernate
    Réponses: 1
    Dernier message: 07/11/2011, 07h16
  2. Problème lors d'un delete avec une relation one-to-many
    Par el_harrathi dans le forum Développement Web en Java
    Réponses: 2
    Dernier message: 01/11/2011, 15h01
  3. [Mapping] Problème avec la relation one-to-many
    Par nadhir84 dans le forum Hibernate
    Réponses: 4
    Dernier message: 16/08/2011, 15h32
  4. Réponses: 30
    Dernier message: 17/05/2011, 12h25
  5. Problème avec une relation maître détail
    Par nb-wissam dans le forum Forms
    Réponses: 2
    Dernier message: 15/06/2010, 11h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo