duandu2159 2016-02-01 12:57
浏览 55
已采纳

一对一的关系学说

I am unable to get my entities to work with a one to one relationship.

/**
 * 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 >

This is the error I get

Type: Doctrine\ORM\ORMInvalidArgumentException

Message: The given entity of type 'Beacon\Entities\UserAccount' (Beacon\Entities\UserAccount@0000000050a7b33800000000160edb7c) has no identity/no id values set. It cannot be added to the identity map.

Where am i going wrong

</div>
  • 写回答

1条回答 默认 最新

  • duaedf6509 2016-02-01 13:45
    关注

    I managed to fix it by doing this

     $this->entityManager->persist($user);
                $this->entityManager->flush();
                $this->entityManager->persist($userAccount);
                $this->entityManager->flush();
    

    Due to

       $this->entityManager->persist($user);
                $this->entityManager->persist($userAccount);
                $this->entityManager->flush(); 
    

    Throwing the error

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度