"Missing value for primary key" sur une entité

Par glochen G Uyirr, il y a 6 ans


Bonjour,

Suite à une migration en Symfony 3.4 , j'ai le problème suivant sur une entité :

request.CRITICAL: Uncaught PHP Exception Doctrine\Common\Proxy\Exception\OutOfBoundsException: "Missing value for primary key idBen on Lea\PrestaBundle\Entity\EgwContact" at /htdocs/vendor/doctrine/common/lib/Doctrine/Common/Proxy/Exception/OutOfBoundsException.php line 40

Voici le code de l'entité :

<?php namespace Lea\PrestaBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; /** * Lea\PrestaBundle\Entity\EgwContact * * @ORM\Table(name="egw_contact") * @ORM\Entity(repositoryClass="Lea\PrestaBundle\Entity\EgwContactRepository") */ class EgwContact { /** * @var integer $idBen * * @ORM\Column(name="id_ben", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $idBen; /** * @var string $idOrganisation * * @ORM\Column(name="id_organisation", type="string", length=64, nullable=true) */ private $idOrganisation; /** * @var integer $idOwner * * @ORM\Column(name="id_owner", type="bigint", nullable=false) */ private $idOwner; /** * @var integer $dateCreation * * @ORM\Column(name="date_creation", type="bigint", nullable=false) */ private $dateCreation; /** * @var integer $idModifier * * @ORM\Column(name="id_modifier", type="bigint", nullable=false) */ private $idModifier; /** * @var integer $dateLastModified * * @ORM\Column(name="date_last_modified", type="bigint", nullable=false) */ private $dateLastModified; etc...... ..... }

Je n'avais absolument le problème en 2.1.

Merci pour votre aide !

1 réponse

glochen G Uyirr, il y a 6 ans

hyper simple : dans une Form appelant l'entité Ewg_contact liée à l'entité Ewg_Categories, il y avait un parametre en dur appelé : je l'ai remplacé par une variable. Et ca marche.

C'est en consultant la fonction getProxy() de la class AbstractProxyFactory.php de Doctrine : il y a une exception qui appelle la fonction OutOfBoundsException::missingPrimaryKeyValue dans lequel il y a le message "Missing value for primary key"

Voici la correction apportée à la Form en question :

$param287=287; $builder->add('categorie', EntityType::class, array( 'class' => 'LeaPrestaBundle:EgwCategories', 'label' => 'catName', 'required' => true, 'empty_data' => null, 'query_builder' => function(EntityRepository $er) { return $er->createQueryBuilder('c') ->where('c.catParent = :parent') ->setParameter('parent',$param287 ) ->orderBy('c.catName','ASC'); }, ));

EXPLICATION : avant, à la place de

il y avait :

->setParameter('parent' , 287 )

ce qui provoquait l'exception de la fonction getProxy de la class AbstractProxyFactory.php de Doctrine.

Donc, ca a l'air correct maintenant.

Merci pour vos messages.