<tfoot id='BfVkD'></tfoot>
      1. <legend id='BfVkD'><style id='BfVkD'><dir id='BfVkD'><q id='BfVkD'></q></dir></style></legend>

        <small id='BfVkD'></small><noframes id='BfVkD'>

        <i id='BfVkD'><tr id='BfVkD'><dt id='BfVkD'><q id='BfVkD'><span id='BfVkD'><b id='BfVkD'><form id='BfVkD'><ins id='BfVkD'></ins><ul id='BfVkD'></ul><sub id='BfVkD'></sub></form><legend id='BfVkD'></legend><bdo id='BfVkD'><pre id='BfVkD'><center id='BfVkD'></center></pre></bdo></b><th id='BfVkD'></th></span></q></dt></tr></i><div id='BfVkD'><tfoot id='BfVkD'></tfoot><dl id='BfVkD'><fieldset id='BfVkD'></fieldset></dl></div>
          <bdo id='BfVkD'></bdo><ul id='BfVkD'></ul>
      2. Doctrine2.3 和 OneToOne 级联持续似乎不起作用

        Doctrine2.3 and OneToOne cascade persist doesn#39;t seem to work(Doctrine2.3 和 OneToOne 级联持续似乎不起作用)
        <i id='eeaDo'><tr id='eeaDo'><dt id='eeaDo'><q id='eeaDo'><span id='eeaDo'><b id='eeaDo'><form id='eeaDo'><ins id='eeaDo'></ins><ul id='eeaDo'></ul><sub id='eeaDo'></sub></form><legend id='eeaDo'></legend><bdo id='eeaDo'><pre id='eeaDo'><center id='eeaDo'></center></pre></bdo></b><th id='eeaDo'></th></span></q></dt></tr></i><div id='eeaDo'><tfoot id='eeaDo'></tfoot><dl id='eeaDo'><fieldset id='eeaDo'></fieldset></dl></div>
          • <bdo id='eeaDo'></bdo><ul id='eeaDo'></ul>
            <tfoot id='eeaDo'></tfoot>
              1. <small id='eeaDo'></small><noframes id='eeaDo'>

                  <tbody id='eeaDo'></tbody>
                <legend id='eeaDo'><style id='eeaDo'><dir id='eeaDo'><q id='eeaDo'></q></dir></style></legend>

                1. 本文介绍了Doctrine2.3 和 OneToOne 级联持续似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有两个实体(User 和 UserPreferences),我想单向映射 OneToOne.

                  I have two entites (User and UserPreferences) that I want to map OneToOne unidirectional.

                  代码如下所示:

                  /**
                   * @ORMTable("users")
                   * @ORMEntity
                   */
                  class User
                  {
                      /**
                       * @ORMColumn(name="id", type="integer")
                       * @ORMId
                       */
                      protected $id;
                  
                      ...
                  
                      /**
                       * @ORMColumn(name="user_preferences_id", type="integer")
                       * @ORMOneToOne
                       * (
                       *      targetEntity="UserPreferences",
                       *      cascade={"persist"}
                       * )
                       */
                      protected $userPreferences;
                  
                      public function __construct() {
                          $this->userPreferences = new UserPreferences();
                      }
                  }
                  
                  
                  /**
                   * @ORMTable("user_preferences")
                   * @ORMEntity
                   */
                  class UserPreferences extends UserPreferencesEntity
                  {
                      /**
                       * @ORMId
                       * @ORMColumn(name="user_id", type="integer")
                       * @ORMGeneratedValue(strategy="AUTO")
                       */
                      protected $id;
                  
                      ...
                  }
                  

                  现在,当一个新用户被创建时,userPreferences 被一个新的 UserPreferences 对象初始化.当尝试持久化 user 时,Doctrine 抛出异常,声明

                  Now when a new User is created, userPreferences is initialized with a new UserPreferences object. When trying to persist user, Doctrine throws an Exception, claiming

                  通过关系 '...EntityUser#userPreferences' 发现了一个新实体,该实体未配置为对实体进行级联持久操作:...EntityUserPreferences@000000003ae25e5700000000a6eaafc9.解决这个问题:要么在这个未知实体上显式调用 EntityManager#persist() 要么配置级联在映射中持久化这个关联,例如@ManyToOne(..,cascade={"persist"}).

                  但我还能做什么?User#userPreferences 被配置为级联持久化,但它没有.我这里有什么问题吗?

                  But what else should I do? User#userPreferences is configured to cascade persist but it doesn't. Am I getting something wrong here?

                  推荐答案

                  好的找到了解决方案:

                  /**
                   * User
                   *
                   * @ORMTable("users")
                   * @ORMEntity
                   */
                  class User extends UserEntity
                  {
                      ...
                  
                      /**
                       * @ORMOneToOne
                       * (
                       *      targetEntity="UserPreferences",
                       *      cascade={"persist", "remove"},
                       *      inversedBy="user"
                       * )
                       */
                      protected $userPreferences;
                  }
                  
                  /**
                   * @ORMTable("user_preferences")
                   * @ORMEntity
                   */
                  class UserPreferences extends UserPreferencesEntity
                  {
                      /**
                       * @ORMColumn(name="id", type="integer")
                       * @ORMId
                       * @ORMGeneratedValue
                       */
                      protected $id;
                  
                      /**
                       * @var int
                       *
                       * @ORMOneToOne(targetEntity="User", mappedBy="id", cascade={"persist", "remove"})
                       */
                      protected $user;
                  
                      ...
                  }
                  

                  首先,我必须指定mappedBy 和inversedBy(我之前已经尝试过,但方向错误 - 拥有方的mappedBy,反方的inversedBy).此外,我认为反面不需要有单独的 id,我也尝试使用拥有方的 id (User#id) 作为主键.

                  First of all I had to specify mappedBy and inversedBy (which I already tried before but in the wrong direction - mappedBy at the owning side, inversedBy at inversed side). Also I thought that the inversed side did not need to have a separate id and I tried to use the id of the owning side (User#id) as primary key for this one too.

                  • http://docs.doctrine-project.org/en/latest/reference/unitofwork-associations.html
                  • http://docs.doctrine-project.org/en/latest/reference/association-mapping.html

                  这篇关于Doctrine2.3 和 OneToOne 级联持续似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                2. <tfoot id='vABFa'></tfoot>
                  <legend id='vABFa'><style id='vABFa'><dir id='vABFa'><q id='vABFa'></q></dir></style></legend>
                      <tbody id='vABFa'></tbody>

                        <small id='vABFa'></small><noframes id='vABFa'>

                        <i id='vABFa'><tr id='vABFa'><dt id='vABFa'><q id='vABFa'><span id='vABFa'><b id='vABFa'><form id='vABFa'><ins id='vABFa'></ins><ul id='vABFa'></ul><sub id='vABFa'></sub></form><legend id='vABFa'></legend><bdo id='vABFa'><pre id='vABFa'><center id='vABFa'></center></pre></bdo></b><th id='vABFa'></th></span></q></dt></tr></i><div id='vABFa'><tfoot id='vABFa'></tfoot><dl id='vABFa'><fieldset id='vABFa'></fieldset></dl></div>
                          <bdo id='vABFa'></bdo><ul id='vABFa'></ul>