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

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

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

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

      2. findBy 与 Symfony2 中的 JOIN 条件

        时间:2023-08-18

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

                  <tbody id='aR7ch'></tbody>

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

                  本文介绍了findBy 与 Symfony2 中的 JOIN 条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有 3 个简单的表:用户、角色、具有多对多关系的 user_x_role.我有 2 个实体:用户和角色.用户实体具有带有关系注释的 $userRoles 属性.在控制器中,我需要获取具有特定角色的所有用户.但我不知道如何在控制器中使用 JOIN.当前错误代码:

                  I have 3 simple tables: user, role, user_x_role with Many-To-Many relation. I have 2 entities: User and Role. User entity has $userRoles property with relation annotation. In Controller I need to fetch all users with specific role. But I don't know how to use JOIN in controller. Current wrong code:

                  $role = $this->getDoctrine()->getRepository('TestBackEndBundle:Role');
                  $roles = $role->findBy(array('name' => 'ROLE_PARTNER'));
                  
                  $user = $this->getDoctrine()->getRepository('TestBackEndBundle:User');
                  $partners = $user->findBy(array('userRoles' => $roles));
                  

                  它显示未定义的索引:joinColumns in ...".但是我在用户实体中有 joinColumns:

                  It thows "Undefined index: joinColumns in ...". But I have joinColumns in User entity:

                  /**
                   * @ORMManyToMany(targetEntity="Role")
                   * @ORMJoinTable(name="user_x_role",
                   *     joinColumns={@ORMJoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE", onUpdate="CASCADE")},
                   *     inverseJoinColumns={@ORMJoinColumn(name="role_id", referencedColumnName="id", onDelete="CASCADE", onUpdate="CASCADE")}
                   * )
                   * @var ArrayCollection
                   */
                  protected $userRoles;
                  

                  推荐答案

                  IMO 最好的方法是为用户实体创建自己的存储库.然后在该存储库中创建像getUsersByRole"这样的方法,您可以在其中使用查询构建器进行所需的查询.

                  IMO the best way for it is create your own repository for User entity. Then in that repository create method like "getUsersByRole" where you make the query you want with query builder.

                   $qb = $this->getEntityManager()->createQueryBuilder();
                   $qb->select('u')
                       ->from('
                  amespaceforUser', 'u')
                       ->join('u.roles', 'r')
                       ->where(...)
                  
                   return $qb->getQuery()->getResult();
                  

                  这篇关于findBy 与 Symfony2 中的 JOIN 条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何获取学说实体属性的类型 下一篇:Symfony2 SoftDeleteable 不适用于 QueryBuilder 删除

                  相关文章

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

                    <bdo id='l3Gv9'></bdo><ul id='l3Gv9'></ul>
                  1. <legend id='l3Gv9'><style id='l3Gv9'><dir id='l3Gv9'><q id='l3Gv9'></q></dir></style></legend>

                    1. <small id='l3Gv9'></small><noframes id='l3Gv9'>

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