mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
How to fix 'Missing value for primary key' #6255
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @denis75chine on GitHub (Jun 21, 2019).
Originally assigned to: @denis75chine on GitHub.
The problem comes back but this time I do not understand what happens:
I am in symfony 3.4
THE entities ARE WELL IN Autoincrement at the level of the primary key
I have the following error:
Uncaught PHP Exception Doctrine \ Common \ Proxy \ Exception \ OutOfBoundsException: "Missing value for primary key contactId on Lea \ PrestaBundle \ Entity \ EgwAddressbook"
My entity :
`<?php
namespace Lea\PrestaBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
Lea\PrestaBundle\Entity\EgwAddressbook
@ORM\Table(name="egw_addressbook")
@ORM\Entity(repositoryClass="Lea\PrestaBundle\Entity\EgwAddressbookRepository")
/
class EgwAddressbook
{
/*
*/
private $contactId;
/**
*/
private $contactTid;
/**
*/
private $contactOwner;
/**
ETC ETC ...
...`
This entity EgwAdressBook is linked with the entity EgwPrestation :
`/**
*/
private $contactPr;
id_contact_prescripteur and contact_id are of the same type (integer) (question already asked)`
When running the EgwPrestation repository (hereinafter), I get the error message:
`$dql=" SELECT p,pr,ac,t
FROM LeaPrestaBundle:EgwPrestation p
inner join p.prestataire pr
left join p.account ac
left join p.dispositif t
".$sqlPlus."
order by p.dateDebut desc";
Thanks for your help!
I keep searching...
@Ocramius commented on GitHub (Jun 22, 2019):
Seems like one of the various tables involved has a
nullprimary key here. That should be filtered out by the hydration process, so something else is happening.Can you reduce this to a simpler integration test case, like the ones in the ORM test suite?
Can't really help without reproducing it.
@denis75chine commented on GitHub (Jun 22, 2019):
Thanks Ocramius for your answer.
It's probably a problem between 2 entities 👍
The link between entities egw_accounts and egw_addressbook is : ACCOUNT_ID
In the database, about the field ACCOUNT_ID there are exactly the same values in entities egw_accounts and egw_addressbook 👍
egw_accounts->ACCOUNT_ID = egw_addressbook->ACCOUNT_ID
SO, perhaps it's in the definition of entities that there's a problem
Remember that, i didnt have the problem in SYMFONY 2 : but in SYMFONY 3.4, the problem appears
THANKS for your help!
ENTITY EGW_ACCOUNTS 👍
class EgwAccounts { /** * @var integer $accountId * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\OneToOne(targetEntity="EgwAddressbook", cascade={"persist", "merge", "remove"}) * @ORM\JoinColumn(name="account_id", referencedColumnName="account_id") */ private $accountId;With the SETTER :
`
/**
* Set accountId
*
* @param Lea\PrestaBundle\Entity\EgwAddressbook $accountId
* @return EgwAccounts
*/
public function setAccountId(\Lea\PrestaBundle\Entity\EgwAddressbook $accountId)
{
$this->accountId = $accountId;
THE ENTITY EGW_ADDRESSBOOK 👍
/** * @var integer $accountId * @ORM\Column(name="account_id", type="integer", nullable=true) */ private $accountId;@Ocramius commented on GitHub (Jun 22, 2019):
Is it intended to be a column or an association? You seem to set an association in a column property...
@denis75chine commented on GitHub (Jun 22, 2019):
The column is account_id : it's a onetoone association.
The setter of account_id in EgwAcccounts :
` /**
* Set accountId
*
* @param Lea\PrestaBundle\Entity\EgwAddressbook $accountId
* @return EgwAccounts
*/
public function setAccountId(\Lea\PrestaBundle\Entity\EgwAddressbook $accountId)
{
$this->accountId = $accountId;
This works in Symfony 2
I am desespared...
@Ocramius commented on GitHub (Jun 22, 2019):
Please read up on association mappings in the docs: associations are not set via
@Column@denis75chine commented on GitHub (Jun 23, 2019):
Thank you for your answer
@denis75chine commented on GitHub (Jun 23, 2019):
I ve got exactly the same problem after changing code (see below)
"Missing value for primary key egwAddressbook on Lea\PrestaBundle\Entity\EgwAccounts"
Entity EgwAccounts :
`
/**
* @ORM\OneToOne(targetEntity="EgwAddressbook", inversedBy="EgwAccounts")
* @ORM\JoinColumn(name="account_id", referencedColumnName="account_id")
* @ORM\Id
*/
protected $egwAddressbook;
entity EgwAddressbook :
`
/**
* @ORM\OneToOne(targetEntity="EgwAccounts", mappedBy="EgwAddressbook")
*/
protected $egwAccounts;
@denis75chine commented on GitHub (Jun 24, 2019):
no answer
stop mission... :(((