小编MaN*_*aNa的帖子

忽略学说中参数为空的 where 语句

您好,我在 Doctrine 的 QueryByilder 中遇到问题。我写了一个有 2 个参数的查询,它们影响 where 语句。如果相关参数为空,我想忽略 where 语句。例如,如果 $play = 3 且 $theater = null,则查询必须返回所有带有 play 3 的门票以及任何剧院,这是我的代码:

public function getAllSearchedTickets($play,$teater){
    return $this->getEntityManager()->createQuery('
        select s from mtadminBundle:ReserveLocation s
        join s.reserve a
        join a.sance b
        where a.acceptCode != 0
        and b.play = :play 
        and b.teater = :teater')
        ->setParameters(array('play'=>$play,'teater'=>$teater))->getResult();
}
Run Code Online (Sandbox Code Playgroud)

谢谢。

sql doctrine symfony

1
推荐指数
1
解决办法
1139
查看次数

标签 统计

doctrine ×1

sql ×1

symfony ×1