<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 条件

        findBy with JOIN criteria in Symfony2(findBy 与 Symfony2 中的 JOIN 条件)

          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 条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的问题)
                • <tfoot id='l3Gv9'></tfoot>

                        <bdo id='l3Gv9'></bdo><ul id='l3Gv9'></ul>
                            <tbody id='l3Gv9'></tbody>
                        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>