Hi i’m having a slight issue with a OneToOne relationship which when runs the below:-
$userToView = $this->view->entityManager->getRepository("Ajfit\Entity\User")
->findOneByName($userName);
This populates as intended but the a relational field called engineerFk, which is a proxy entity has the identifier field set to [] but with the value set correctly, see below:-

My User entity is this:-
class User extends PersistentObject
{
/**
* @var integer $pk
*
* @ORM\Column(name="pk", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $pk;
/**
* @var integer $engineerFk
* @ORM\OneToOne(targetEntity="Ajfit\Entity\Engineer")
* @ORM\JoinColumn(name="pk", referencedColumnName="user_fk")
*/
protected $engineerFk;
}
My engineer entity setup like this:-
class Engineer extends PersistentObject
{
/**
* @var integer $pk
*
* @ORM\Column(name="pk", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
}
protected $pk;
And my sql in the database is this:-
/*user table*/
CREATE TABLE `user` (
`pk` int(10) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`pk`)
) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8 COLLATE=utf8_bin
/*engineer table */
CREATE TABLE `engineer` (
`pk` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_fk` int(10) unsigned NOT NULL,
PRIMARY KEY (`pk`),
KEY `engineer_user_fk` (`user_fk`),
CONSTRAINT `engineer_user_fk` FOREIGN KEY (`user_fk`) REFERENCES `user` (`pk`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8
Any help reagrding this problem would be much apprieciated.
Thanks
Andrew
I think that you’re defining the owning side of the relationship on the wrong entity. It should be defined on the entity that owns the foreign key.
I’m not comfortable with annotations, so I’ll use YAML to describe the association.
So, for the Engineer entity, you should have something like:
Then, for the User entity, the config should be like this:
Read this for details.
Also, with such association mapping, the Doctrine 2 console tool will generate slightly different entity classes.