Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Blocker
-
Resolution: Invalid
-
Affects Version/s: 2.1.5
-
Fix Version/s: None
-
Component/s: ORM
-
Security Level: All
-
Labels:None
Description
Hi,
In first time, sorry for my bad english.
The feature Foreign key as Primary does not work as intended.
The CLI tool report an error on validating mapping:
The referenced column name 'pk_agent' does not have a corresponding field with this column name on the class 'BddP\Model\Entity\Sd\Contact'.
If I run the application, many features works: querying, entity population.
But for persist a new Agent without associated entities for OneToOne; the ORM report :
PDOException: SQLSTATE[23502]: Not null violation on "pk" column
And If I comment all OneToOne, the persist work.
Thank you in advance for your response.
Agent.php
/** * @Entity(repositoryClass="BddP\Model\Entity\Repository\Sd\Agent") * @Table(name="agent") */ class Agent extends AEntity { /** * Agent ID * @var int * * @Id * @GeneratedValue * @Column(name="pk", type="integer", nullable=false) */ private $pk; /** * @var BddP\Model\Entity\Sd\Contact * * @OneToOne(targetEntity="BddP\Model\Entity\Sd\Contact", cascade={"remove,merge,detach"}, mappedBy="agent") * @JoinColumn(name="pk", referencedColumnName="pk_agent") */ private $contact; [...] }
Contact.php
/** * @Table(name="contact") */ class Contact extends AEntity { /** * The agent * @var BddP\Model\Entity\Sd\Agent * * @Id * @OneToOne(targetEntity="BddP\Model\Entity\Sd\Agent", inversedBy="contact") * @JoinColumn(name="pk_agent", referencedColumnName="pk") */ private $agent; [...] }
In addition,
1. The generated SQL from CLI tool is correct.
2. I think the problem is located when the associated entity request the Primary Key.