如何在学说标准中更改命令的顺序

时间:2015-01-02 19:36:28

标签: symfony doctrine-orm

所以这就是我使用标准的方式:

$criteria = Criteria::create();
$criteria->andWhere($criteria->expr()->eq('author', /**/));
$criteria->orWhere($criteria->expr()->eq('author', /**/));
$criteria->orWhere($criteria->expr()->eq('author', /**/));

导致这个sql命令:

WHERE 

      (
        (
          t0.author_id = ? 
          OR t0.author_id = ?
        ) 
        OR t0.author_id = ?
      ) 

如果我需要这个怎么办?

WHERE 

      (
        (
          t0.author_id = ? 
          OR t0.author_id = ?
          OR t0.author_id = ?
        )
      ) 

有什么方法可以改变括号的关联吗?

1 个答案:

答案 0 :(得分:2)

试试这个:

$criteria = Criteria::create();
$criteria->andWhere(
    $criteria->expr()->orX(
        $criteria->expr()->eq('author', /**/),
        $criteria->expr()->eq('author', /**/),
        $criteria->expr()->eq('author', /**/)
    )
);