• <tfoot id='rYbJx'></tfoot>

    • <bdo id='rYbJx'></bdo><ul id='rYbJx'></ul>

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

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

        Doctrine 2 多对多级联

        Doctrine 2 ManyToMany cascade(Doctrine 2 多对多级联)

          <bdo id='OoEIV'></bdo><ul id='OoEIV'></ul>

        • <legend id='OoEIV'><style id='OoEIV'><dir id='OoEIV'><q id='OoEIV'></q></dir></style></legend>

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

              <tfoot id='OoEIV'></tfoot>
                <tbody id='OoEIV'></tbody>
            • <i id='OoEIV'><tr id='OoEIV'><dt id='OoEIV'><q id='OoEIV'><span id='OoEIV'><b id='OoEIV'><form id='OoEIV'><ins id='OoEIV'></ins><ul id='OoEIV'></ul><sub id='OoEIV'></sub></form><legend id='OoEIV'></legend><bdo id='OoEIV'><pre id='OoEIV'><center id='OoEIV'></center></pre></bdo></b><th id='OoEIV'></th></span></q></dt></tr></i><div id='OoEIV'><tfoot id='OoEIV'></tfoot><dl id='OoEIV'><fieldset id='OoEIV'></fieldset></dl></div>
                1. 本文介绍了Doctrine 2 多对多级联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  是否可以在 Doctrine 2 中创建两个多对多相关的对象并仅在其中一个上调用 persist 以保存两者?

                  Is it possible in Doctrine 2 to create two objects that are many to many related and call persist only on one of them to save both?

                  用户实体:

                      /**
                   * Owning Side
                   *
                   * @ManyToMany(targetEntity="Role", inversedBy="users", cascade={"persist"})
                   * @JoinTable(name="user_roles",
                   *      joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")},
                   *      inverseJoinColumns={@JoinColumn(name="role_id", referencedColumnName="id")}
                   *      )
                   */
                  public $roles;
                  

                  角色实体:

                      /**
                   * Inverse Side
                   *
                   * @ManyToMany(targetEntity="User", mappedBy="roles")
                   */
                  public $users;
                  

                  保存:

                      $role = new Role();
                  
                      $user = new User();
                  
                  $user->roles->add($role);
                  $role->users->add($user);
                  
                  $em->persist($user);
                  $em->flush();
                  

                  它不起作用并引发错误通过未配置为级联持久化操作的关系找到新实体:EntitiesRole@0000000004a29c11000000005c48cb75.显式持久化新实体或在关系上配置级联持久化操作."

                  It doesn't work and trows an error "A new entity was found through a relationship that was not configured to cascade persist operations: EntitiesRole@0000000004a29c11000000005c48cb75. Explicitly persist the new entity or configure cascading persist operations on the relationship."

                  推荐答案

                  您应该将 cascade={"persist"} 应用于 Role 实体.

                  You should apply cascade={"persist"} to the Role entity.

                  不是 Doctrine 专家,但我认为 Doctrine 检查关联实体的级联选项.

                  Not an expert on Doctrine, but I think Doctrine checks the associated entity for cascading options.

                  由于您将持久 用户 角色,它会检查角色 实体,如果它应该被级联持久化.

                  Since you are cascading the persist from Users to Roles, it checks the Role entity if it should be persisted with cascade.

                  这篇关于Doctrine 2 多对多级联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  When should use doctrine ORM and when zend-db-table?(什么时候应该使用学说 ORM,什么时候应该使用 zend-db-table?)
                  Doctrine - self-referencing entity - disable fetching of children(Doctrine - 自引用实体 - 禁用获取子项)
                  Doctrine 2, query inside entities(原则 2,实体内部查询)
                  Complex WHERE clauses using the PHP Doctrine ORM(使用 PHP Doctrine ORM 的复杂 WHERE 子句)
                  Doctrine - OneToMany relation, all result row doesn#39;t fetch in object(Doctrine - OneToMany 关系,所有结果行不获取对象)
                  Doctrine and unrefreshed relationships(教义和未更新的关系)

                      <tbody id='ZFcoJ'></tbody>

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

                  1. <i id='ZFcoJ'><tr id='ZFcoJ'><dt id='ZFcoJ'><q id='ZFcoJ'><span id='ZFcoJ'><b id='ZFcoJ'><form id='ZFcoJ'><ins id='ZFcoJ'></ins><ul id='ZFcoJ'></ul><sub id='ZFcoJ'></sub></form><legend id='ZFcoJ'></legend><bdo id='ZFcoJ'><pre id='ZFcoJ'><center id='ZFcoJ'></center></pre></bdo></b><th id='ZFcoJ'></th></span></q></dt></tr></i><div id='ZFcoJ'><tfoot id='ZFcoJ'></tfoot><dl id='ZFcoJ'><fieldset id='ZFcoJ'></fieldset></dl></div>
                      • <tfoot id='ZFcoJ'></tfoot>
                        <legend id='ZFcoJ'><style id='ZFcoJ'><dir id='ZFcoJ'><q id='ZFcoJ'></q></dir></style></legend>

                          <bdo id='ZFcoJ'></bdo><ul id='ZFcoJ'></ul>