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

      1. 学说 2 多对多级联

        时间:2023-07-14
      2. <tfoot id='wcEqQ'></tfoot>
            <tbody id='wcEqQ'></tbody>

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

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

                  本文介绍了学说 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.

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

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

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

                • <tfoot id='H7SjO'></tfoot>
                • <small id='H7SjO'></small><noframes id='H7SjO'>

                  • <bdo id='H7SjO'></bdo><ul id='H7SjO'></ul>
                      <tbody id='H7SjO'></tbody>

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