如何编写具有多个条件的 Doctrine 查询


How to write a Doctrine Query with multiple conditions?

我正在尝试编写满足以下条件的教义查询:

published = 1
AND 
subsection = "gui" OR "lvo" OR "tnn" OR "wer"

这是我所拥有的:

$getPrograms = Doctrine::getTable('Program')
  ->createQuery()
  ->where('published=?', '1')
  ->andWhere('subsection=?', 'gui')
  ->orWhere('subsection=?', 'lvo')
  ->orWhere('subsection=?', 'tnn')
  ->orWhere('subsection=?', 'wer')
  ->orderBy('title ASC')
  ->execute();

这是提取正确的小节记录,但提取记录所有已发布的记录,而不是仅提取设置为 1 的记录。

我觉得我需要隔离两个条件(这个和(这个或这个或这个)),但我不知道怎么做。

把你的OR放在andWhere

$getPrograms = Doctrine::getTable('Program')
  ->createQuery()
  ->where('published=?', '1')
  ->andWhere(
    'subsection=? OR subsection=? OR subsection=? OR subsection=?', 
    array('gui', 'lvo', 'tnn', 'wer')
  )
  ->orderBy('title ASC')
  ->execute();