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 :

Erreur sur une association ManyToMany [3.x]


Sujet :

Symfony PHP

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Octobre 2016
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Octobre 2016
    Messages : 37
    Points : 37
    Points
    37
    Par défaut Erreur sur une association ManyToMany
    Bonjour,

    J'ai une association entre l'entité et l'entité .

    Voici mes classes :

    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
    <?php
     
    namespace VS\CrmBundle\Entity;
     
    use Doctrine\Common\Collections\ArrayCollection;
    use Doctrine\ORM\Mapping as ORM;
     
    /**
     * Staff
     *
     * @ORM\Table(name="staff")
     * @ORM\Entity(repositoryClass="VS\CrmBundle\Repository\StaffRepository")
     */
    class Staff extends User
    {
        /**
         * @var int
         *
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        protected $id;
     
        /**
         * @var string
         *
         * @ORM\Column(name="staff_role", type="string", length=100)
         */
        private $staffRole;
     
        /**
         * @var ArrayCollection
         *
         * @ORM\ManyToMany(targetEntity="Nursery", inversedBy="staff", cascade={"persist"})
         * @ORM\JoinTable(name="nursery_staff",
         *     joinColumns={@ORM\JoinColumn(name="staff_id", referencedColumnName="id")},
         *     inverseJoinColumns={@ORM\JoinColumn(name="nursery_id", referencedColumnName="id")}
         *  )
         */
        private $nurseries;
     
        /**
         * Staff constructor.
         */
        public function __construct()
        {
            parent::__construct();
            $this->nurseries = new ArrayCollection();
        }
     
        /**
         * Get id
         *
         * @return int
         */
        public function getId()
        {
            return $this->id;
        }
     
        /**
         * Set staffRole
         *
         * @param string $staffRole
         *
         * @return Staff
         */
        public function setStaffRole($staffRole)
        {
            $this->staffRole = $staffRole;
     
            return $this;
        }
     
        /**
         * Get staffRole
         *
         * @return string
         */
        public function getStaffRole()
        {
            return $this->staffRole;
        }
     
        /**
         * @param Nursery $nursery
         */
        public function addNurseries(Nursery $nursery)
        {
            $nursery->addStaff($this);
            $this->nurseries[] = $nursery;
        }
     
        /**
         * @param Nursery $nursery
         */
        public function removeNurseries(Nursery $nursery)
        {
            $this->nurseries->removeElement($nursery);
        }
     
        /**
         * @return ArrayCollection
         */
        public function getNurseries()
        {
            return $this->nurseries;
        }
    }
    et

    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
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    <?php
     
    namespace VS\CrmBundle\Entity;
     
    use Doctrine\Common\Collections\ArrayCollection;
    use Doctrine\ORM\Mapping as ORM;
     
    /**
     * Nursery
     *
     * @ORM\Table(name="Nursery")
     * @ORM\Entity(repositoryClass="VS\CrmBundle\Repository\NurseryRepository")
     */
    class Nursery
    {
        /**
         * @var int
         *
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        private $id;
     
        /**
         * @var string
         *
         * @ORM\Column(name="name", type="string", length=100)
         */
        private $name;
     
        /**
         * @var string
         *
         * @ORM\Column(name="phone_number", type="string", length=15, nullable=true)
         */
        private $phoneNumber;
     
        /**
         * @var \DateTime
         *
         * @ORM\Column(name="created_at", type="datetime")
         */
        private $createdAt;
     
        /**
         * @var \DateTime
         *
         * @ORM\Column(name="updated_at", type="datetime", nullable=true)
         */
        private $updatedAt;
     
        /**
         * @var Address
         *
         * @ORM\OneToOne(targetEntity="Address", inversedBy="nursery", cascade={"persist"})
         * @ORM\JoinColumn(name="fk_address_id", referencedColumnName="id")
         */
        private $address;
     
     
        /**
         * @var ArrayCollection
         *
         * @ORM\ManyToMany(targetEntity="Staff", mappedBy="nurseries", cascade={"persist"})
         * @ORM\JoinTable(name="nursery_staff")
         */
        private $staff;
     
        /**
         * @var ArrayCollection
         *
         * @ORM\OneToMany(targetEntity="Schedule", mappedBy="nursery", cascade={"persist"})
         */
        private $schedule;
     
        /**
         * @var ArrayCollection
         *
         * @ORM\OneToMany(targetEntity="Contact", mappedBy="nursery", cascade={"persist"})
         */
        private $contacts;
     
        /**
         * @var ArrayCollection
         *
         * @ORM\OneToMany(targetEntity="RegisterRecord", mappedBy="nursery", cascade={"persist"})
         */
        private $registerRecords;
     
        /**
         * Nursery constructor.
         */
        public function __construct()
        {
            $this->staff = new ArrayCollection();
            $this->schedule = new ArrayCollection();
            $this->createdAt = new \DateTime();
            $this->contacts = new ArrayCollection();
            $this->registerRecord = new ArrayCollection();
        }
     
        /**
         * Get id
         *
         * @return int
         */
        public function getId()
        {
            return $this->id;
        }
     
        /**
         * Set name
         *
         * @param string $name
         *
         * @return Nursery
         */
        public function setName($name)
        {
            $this->name = $name;
     
            return $this;
        }
     
        /**
         * Get name
         *
         * @return string
         */
        public function getName()
        {
            return $this->name;
        }
     
        /**
         * Set phoneNumber
         *
         * @param string $phoneNumber
         *
         * @return Nursery
         */
        public function setPhoneNumber($phoneNumber)
        {
            $this->phoneNumber = $phoneNumber;
     
            return $this;
        }
     
        /**
         * Get phoneNumber
         *
         * @return string
         */
        public function getPhoneNumber()
        {
            return $this->phoneNumber;
        }
     
        /**
         * Set createdAt
         *
         * @param \DateTime $createdAt
         *
         * @return Nursery
         */
        public function setCreatedAt($createdAt)
        {
            $this->createdAt = $createdAt;
     
            return $this;
        }
     
        /**
         * Get createdAt
         *
         * @return \DateTime
         */
        public function getCreatedAt()
        {
            return $this->createdAt;
        }
     
        /**
         * Set updatedAt
         *
         * @param \DateTime $updatedAt
         *
         * @return Nursery
         */
        public function setUpdatedAt($updatedAt)
        {
            $this->updatedAt = $updatedAt;
     
            return $this;
        }
     
        /**
         * Get updatedAt
         *
         * @return \DateTime
         */
        public function getUpdatedAt()
        {
            return $this->updatedAt;
        }
     
        /**
         * Set address
         *
         * @param \VS\CrmBundle\Entity\Address $address
         *
         * @return Nursery
         */
        public function setAddress(\VS\CrmBundle\Entity\Address $address = null)
        {
            $this->address = $address;
     
            return $this;
        }
     
        /**
         * Get address
         *
         * @return \VS\CrmBundle\Entity\Address
         */
        public function getAddress()
        {
            return $this->address;
        }
     
        /**
         * Add staff
         *
         * @param \VS\CrmBundle\Entity\Staff $staff
         *
         * @return Nursery
         */
        public function addStaff(\VS\CrmBundle\Entity\Staff $staff)
        {
            $this->staff[] = $staff;
     
            return $this;
        }
     
        /**
         * Remove staff
         *
         * @param \VS\CrmBundle\Entity\Staff $staff
         */
        public function removeStaff(\VS\CrmBundle\Entity\Staff $staff)
        {
            $this->staff->removeElement($staff);
        }
     
        /**
         * Get staff
         *
         * @return \Doctrine\Common\Collections\Collection
         */
        public function getStaff()
        {
            return $this->staff;
        }
     
        /**
         * Add schedule
         *
         * @param \VS\CrmBundle\Entity\Schedule $schedule
         *
         * @return Nursery
         */
        public function addSchedule(\VS\CrmBundle\Entity\Schedule $schedule)
        {
            $this->schedule[] = $schedule;
     
            return $this;
        }
     
        /**
         * Remove schedule
         *
         * @param \VS\CrmBundle\Entity\Schedule $schedule
         */
        public function removeSchedule(\VS\CrmBundle\Entity\Schedule $schedule)
        {
            $this->schedule->removeElement($schedule);
        }
     
        /**
         * Get schedule
         *
         * @return \Doctrine\Common\Collections\Collection
         */
        public function getSchedule()
        {
            return $this->schedule;
        }
     
        public function __toString()
        {
            $stringDeMalade = $this->getName().' '.$this->getAddress()->getLocality()->getPostalCode().' '.$this->getAddress()->getLocality()->getName();
            return $stringDeMalade;
        }
     
        /**
         * Add contact
         *
         * @param \VS\CrmBundle\Entity\Contact $contact
         *
         * @return Nursery
         */
        public function addContact(\VS\CrmBundle\Entity\Contact $contact)
        {
            $this->contacts[] = $contact;
     
            return $this;
        }
     
        /**
         * Remove contact
         *
         * @param \VS\CrmBundle\Entity\Contact $contact
         */
        public function removeContact(\VS\CrmBundle\Entity\Contact $contact)
        {
            $this->contacts->removeElement($contact);
        }
     
        /**
         * Get contacts
         *
         * @return \Doctrine\Common\Collections\Collection
         */
        public function getContacts()
        {
            return $this->contacts;
        }
     
        /**
         * Add registerRecord
         *
         * @param \VS\CrmBundle\Entity\RegisterRecord $registerRecord
         *
         * @return Nursery
         */
        public function addRegisterRecord(\VS\CrmBundle\Entity\RegisterRecord $registerRecord)
        {
            $this->registerRecords[] = $registerRecord;
     
            return $this;
        }
     
        /**
         * Remove registerRecord
         *
         * @param \VS\CrmBundle\Entity\RegisterRecord $registerRecord
         */
        public function removeRegisterRecord(\VS\CrmBundle\Entity\RegisterRecord $registerRecord)
        {
            $this->registerRecords->removeElement($registerRecord);
        }
     
        /**
         * Get registerRecords
         *
         * @return \Doctrine\Common\Collections\Collection
         */
        public function getRegisterRecords()
        {
            return $this->registerRecords;
        }
    }
    J'ai mon controlleur dans lequel je demande d'afficher le dashboard d'une crèche (avec un id donné) qui est liée à l'utilisateur courant :

    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
       public function dashboardAction($nursery_id)
        {
            $currentUser = $this->get('security.token_storage')->getToken()->getUser();
            $nurseryRepo = $this->getDoctrine()->getRepository('VSCrmBundle:Nursery');
     
            $nursery = $nurseryRepo->findOneBy(array(
                'id' => $nursery_id,
                'staff' => $currentUser
            ));
     
            //TODO TEST THIS
            if(!$nursery)
            {
                throw $this->createNotFoundException("The nursery has not been found or you are not allowed to access it.");
            }
     
            return $this->render("VSCrmBundle:Manager:dashboard.html.twig", array(
                'nursery' => $nursery
            ));
        }
    et j'ai un dropdown qui me montre tous les dashboards auxquels l'utilisateur courant a accès :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dashboards<span class="caret"></span></a>
                            <ul class="dropdown-menu">
                                {% if is_granted('ROLE_MANAGER') %}
                                    <li class="dropdown-header">Nurseries</li>
                                    {% for nursery in app.user.nurseries %}
                                        <li><a href="{{ path('vs_crm_manager_dashboard', {'nursery_id' : nursery.id}) }}">{{ nursery.name }} dashboard</a></li>
                                    {% endfor %}
    {% endif %}
        </ul>
        </li>
    Le problème est que quand je click sur une des crèche proposées j'ai l'erreur suivante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Catchable Fatal Error: Argument 1 passed to Doctrine\ORM\Mapping\DefaultQuoteStrategy::getJoinTableName() must be of the type array, null given, called in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php on line 1669 and defined
    Et les logs :
    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
     
    [1] Symfony\Component\Debug\Exception\ContextErrorException: Catchable Fatal Error: Argument 1 passed to Doctrine\ORM\Mapping\DefaultQuoteStrategy::getJoinTableName() must be of the type array, null given, called in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php on line 1669 and defined
        at n/a
            in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\DefaultQuoteStrategy.php line 97
     
        at Symfony\Component\Debug\ErrorHandler->handleError('4096', 'Argument 1 passed to Doctrine\ORM\Mapping\DefaultQuoteStrategy::getJoinTableName() must be of the type array, null given, called in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php on line 1669 and defined', 'C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\DefaultQuoteStrategy.php', '97', array())
            in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\DefaultQuoteStrategy.php line 97
     
        at Doctrine\ORM\Mapping\DefaultQuoteStrategy->getJoinTableName(null, object(ClassMetadata), object(MySQL57Platform))
            in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php line 1669
     
        at Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectConditionStatementColumnSQL('staff', null)
            in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php line 1582
     
        at Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectConditionStatementSQL('staff', object(Staff), null)
            in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php line 1724
     
        at Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectConditionSQL(array('id' => '4', 'staff' => object(Staff)), null)
            in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php line 1058
     
        at Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectSQL(array('id' => '4', 'staff' => object(Staff)), null, null, '1', null, null)
            in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php line 710
     
        at Doctrine\ORM\Persisters\Entity\BasicEntityPersister->load(array('id' => '4', 'staff' => object(Staff)), null, null, array(), null, '1', null)
            in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\EntityRepository.php line 196
     
        at Doctrine\ORM\EntityRepository->findOneBy(array('id' => '4', 'staff' => object(Staff)))
            in C:\wamp64\www\app\src\VS\CrmBundle\Controller\ManagerController.php line 21
     
        at VS\CrmBundle\Controller\ManagerController->dashboardAction('4')
            in  line 
     
        at call_user_func_array(array(object(ManagerController), 'dashboardAction'), array('4'))
            in C:\wamp64\www\app\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php line 153
     
        at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
            in C:\wamp64\www\app\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php line 68
     
        at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
            in C:\wamp64\www\app\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php line 169
     
        at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
            in C:\wamp64\www\app\web\app_dev.php line 28
    Je ne comprends pas d'ou vient le problème...

    Merci pour votre aide.

  2. #2
    Nouveau membre du Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Octobre 2016
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Octobre 2016
    Messages : 37
    Points : 37
    Points
    37
    Par défaut
    Il semble que la fonction findOneBy(array('a' => $a)) ne fonctionne pas avec une association ManyToMany. Problème résolu en enlevant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    'staff' => $currentUser
    du contrôleur.

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

Discussions similaires

  1. Réponses: 8
    Dernier message: 23/01/2020, 09h34
  2. Erreur sur une boite de dialogue WXWIDGETS
    Par barbarello dans le forum Autres éditeurs
    Réponses: 6
    Dernier message: 06/01/2006, 20h46
  3. Réponses: 8
    Dernier message: 01/03/2005, 16h01
  4. Réponses: 4
    Dernier message: 14/06/2004, 16h18
  5. Erreur sur une fonction avec des paramètres
    Par Elois dans le forum PostgreSQL
    Réponses: 2
    Dernier message: 05/05/2004, 21h00

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