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

Symfony PHP Discussion :

PB pour persister une entité [2.x]


Sujet :

Symfony PHP

  1. #1
    Membre averti
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2009
    Messages
    351
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2009
    Messages : 351
    Points : 342
    Points
    342
    Par défaut PB pour persister une entité
    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 :
    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;
      }
     
    }
    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
    <?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;
        }
    }
    Merci de votre aide.

  2. #2
    Membre expérimenté
    Homme Profil pro
    Inscrit en
    Septembre 2009
    Messages
    875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Septembre 2009
    Messages : 875
    Points : 1 313
    Points
    1 313
    Par défaut
    ton controlleur qui fait le create stp :]

  3. #3
    Membre averti
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2009
    Messages
    351
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2009
    Messages : 351
    Points : 342
    Points
    342
    Par défaut
    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 voirListeCategoriesAction(Operation $operation) {
     
            if ($operation === null)
                throw $this->createNotFoundException('Operation[id=' . $operation->getId() . '] inexistante.');   
     
            $form = $this->createForm(new OperationCategorieType(), $operation);
            $request = $this->getRequest();
     
            if ($request->getMethod() == 'POST') {
     
                $form->bind($request);
     
                if ($form->isValid()) {                
                    $em = $this->getDoctrine()->getManager();
                    $em->persist($operation);              
                    $em->flush();
                    $this->get('session')->getFlashBag()->add('info', "Les catégories de l'opération sont bien modifiées");
                    return $this->redirect($this->generateUrl('assetreportmanager_voirListeCategories', array('id' => $operation->getId())));
                }
            }
            return $this->render('AssetReportManagerBundle:ReportManager:voirListeCategories.html.twig', array('form' => $form->createView(),'operation' => $operation));       
        }
    Le formulaire de création des catégories :
    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
    <?php
     
    namespace Asset\ReportManagerBundle\Form;
     
    use Symfony\Component\Form\AbstractType;
    use Symfony\Component\Form\FormBuilderInterface;
    use Symfony\Component\OptionsResolver\OptionsResolverInterface;
    use Symfony\Component\Form\FormEvents;
    use Symfony\Component\Form\FormEvent;
     
    class OperationCategorieType extends AbstractType
    {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
            $builder->add('categories', 'collection', array('type'         => new CategorieSimpleType(),
                                                  'allow_add'    => true,
                                                  'allow_delete' => true,
                                                  'by_reference' => false,
                              ))
              ;    
      }  
     
      // Pour définir autour de quel objet est construit le formulaire (autour d'Operation)
      public function setDefaultOptions(OptionsResolverInterface $resolver) {
        $resolver->setDefaults(array( 'data_class' => 'Asset\ReportManagerBundle\Entity\Operation'));
      }
     
      public function getName()
      {
        return 'asset_reportmanagerbundle_operationtype';
      }  
    }
    CategorieSimpleType :
    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
    <?php
     
    namespace Asset\ReportManagerBundle\Form;
     
    use Symfony\Component\Form\AbstractType;
    use Symfony\Component\Form\FormBuilderInterface;
    use Symfony\Component\OptionsResolver\OptionsResolverInterface;
     
    use Symfony\Component\Form\FormInterface;
     
    class CategorieSimpleType extends AbstractType
    {
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            $builder->add('nom', 'text', array("label" => false)); 
        }     
     
        public function setDefaultOptions(OptionsResolverInterface $resolver)
        {
            $resolver->setDefaults(array('data_class' => 'Asset\ReportManagerBundle\Entity\Categorie'));       
        }
     
        public function getName()
        {
            return 'asset_reportmanagerbundle_categorietype';
        }
    }

  4. #4
    Membre averti
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2009
    Messages
    351
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2009
    Messages : 351
    Points : 342
    Points
    342
    Par défaut
    J'ai trouvé :

    J'ai inversé le propriétaire de la relation (voir code) et j'ai modifié le constructeur de Categorie en ajoutant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $this->mailing = new \Asset\ReportManagerBundle\Entity\Mailing;
            $this->mailing->setCategorie($this);
    Voici le code complet des deux entités :
    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
    <?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", mappedBy="categorie", cascade={"persist", "remove"})
       */
        private $mailing;   
     
        public function __construct()
        {     
            $this->fichiers = new \Doctrine\Common\Collections\ArrayCollection();
            $this->mailing = new \Asset\ReportManagerBundle\Entity\Mailing;
            $this->mailing->setCategorie($this);
        }         
     
        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 \Asset\ReportManagerBundle\Entity\Mailing $mailing
       * @return Categorie
       */
      public function setMailing(\Asset\ReportManagerBundle\Entity\Mailing $mailing)
      {
        $this->mailing = $mailing;
        return $this;
      }
     
      /**
       * @return \Asset\ReportManagerBundle\Entity\Mailing 
       */
      public function getMailing()
      {
        return $this->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
    <?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", inversedBy="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();
          $this->texte = 'Texte par défaut pour ce mailing.';
      }
     
      /**
       * @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;
    //    }   
     
     
        /**
         * Set categorie
         *
         * @param \Asset\ReportManagerBundle\Entity\Categorie $categorie
         * @return Mailing
         */
        public function setCategorie(\Asset\ReportManagerBundle\Entity\Categorie $categorie)
        {
            $this->categorie = $categorie;
     
            return $this;
        }
     
        /**
         * Get categorie
         *
         * @return \Asset\ReportManagerBundle\Entity\Categorie 
         */
        public function getCategorie()
        {
            return $this->categorie;
        }   
    }
    Cette solution fonctionne parfaitement mais je ne sais pas si c'est très correct de faire comme ça. Il y a quelque chose qui m'échappe, je pensais qu'en mettant un "persist" l'entité à l'autre bout de la relation était automatiquement créée lors de la création de l'entité propriétaire. Est-ce que tu peux m'expliquer ?

    En tout cas merci qu'en même de ton aide

    Ps : Je laisse le sujet ouvert encore un moment au cas où quelqu'un à une explication à me donner.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Persister une entité et flush "plus tard"
    Par solofein dans le forum Doctrine2
    Réponses: 5
    Dernier message: 30/09/2014, 01h45
  2. [2.x] Persister une entité créée manuellement
    Par Sephiroth Lune dans le forum Symfony
    Réponses: 7
    Dernier message: 14/11/2013, 13h56
  3. [2.x] Impossible de Persister une entité
    Par hx.jonathan dans le forum Symfony
    Réponses: 10
    Dernier message: 03/10/2011, 18h37
  4. Réponses: 12
    Dernier message: 27/05/2010, 20h01
  5. besoin d'aide pour intégrer une entité dans un MCD
    Par barkleyfr dans le forum Schéma
    Réponses: 17
    Dernier message: 13/10/2005, 13h29

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