我无法让我的实体与一对一的关系合作。
/**
* Beacon\Entities\User
*/
class User {
/**
* @var string
*/
private $firstName;
/**
* @var string
*/
private $lastName;
/**
* @var string
*/
private $userName;
/**
* @var string
*/
private $password;
/**
* @var string
*/
private $email;
/**
* @var string
*/
private $mobile;
/**
* @var string
*/
private $address1;
/**
* @var string
*/
private $address2;
/**
* @var \DateTime
*/
private $dateCreated;
/**
* @var integer
*/
private $id;
class UserAccount {
/**
* @var integer
*/
private $ispaid;
/**
* @var \Beacon\Entities\User
*/
private $id;
<? xml version = "1.0"
encoding = "utf-8" ?>
< doctrine - mapping xmlns = "http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi: schemaLocation = "http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd" >
< entity name = "Beacon\Entities\UserAccount"
table = "user_account" >
< id name = "id"
association - key = "true" / >
< field name = "ispaid"
type = "integer"
column = "ispaid"
nullable = "true" >
< options >
< option name = "unsigned" / >
< /options>
</field >
< one - to - one field = "id"
target - entity = "Beacon\Entities\User"
fetch = "LAZY" >
< join - columns >
< join - column name = "id"
referenced - column - name = "id" / >
< /join-columns>
</one - to - one >
< /entity>
</doctrine - mapping >
这是我得到的错误
输入:Doctrine \ ORM \ ORMInvalidArgumentException
消息:“Beacon \ Entities \ UserAccount”类型的给定实体 (Beacon \ Entities \ UserAccount @ 0000000050a7b33800000000160edb7c)没有 identity / no id值设置。它无法添加到身份图中。
我哪里出错
答案 0 :(得分:0)
我设法通过这样做来解决这个问题
$this->entityManager->persist($user);
$this->entityManager->flush();
$this->entityManager->persist($userAccount);
$this->entityManager->flush();
由于
$this->entityManager->persist($user);
$this->entityManager->persist($userAccount);
$this->entityManager->flush();
抛出错误