doukan6564 2013-08-03 07:12
浏览 33
已采纳

如何限制实体属性在学说中提取关联实体?

I have an issue where I would like to use use the first entity I queried to load it's associated one to many entities. The issue I'm having is I would like to limit the query for "$campaignLogs" to "status" == "public"

The example below does not work, but shows what I would like to do. I found out already that you can't use where() on an array collection as it's already equivalently set or processed the query.

    $em = $this->getDoctrine()->getManager();
    $campaign = $em->getRepository('STLDevRPGBundle:Campaign\Campaign')->findOneByTitle($slug);
    // This is what doesn't work, I have to change the "get" somehow
    // or does this have to be a custom repository function?
    $campaignLogs = $campaign->getCampaignLogs()->where(array("status = 'public'"));
  • 写回答

1条回答 默认 最新

  • doukan4795 2013-08-03 08:16
    关注

    You could add an optional parameter to your already existing custom method. Do something like this:

    public function findOneByTitle($slug, $status = null)
    {
        $qb = $this->createQueryBuilder('c');
        $qb->select('c');
           ->where('c.title = :title')
           ->setParameter('title', $slug);
        if ($status !== null) {
            $qb->join('c.campaignLogs', 'l');
            $qb->where('l.status = :status')
               ->setParameter('status', $status);
        }
        return $qb->getQuery()->getSingleResult();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办