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 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?