0

当我建立一个查询时,学说自动删除了“()”。

这是我的查询:

$query = MstFontTable::getInstance()->createQuery('msf');
$query->where('(full_font_name LIKE ? OR
                full_font_name LIKE ? OR
                full_font_name LIKE ? OR
                full_font_name = ? OR
                font_name = ?)', array(trim($fontName) . ',%',
                                       '%,' . trim($fontName),
                                       '%,' . trim($fontName) . ',%',
                                       trim($fontName),
                                       trim($fontName)
                                      )
             );
$query->andWhere('((tenant_id = 0 OR tenant_id = ?))', array(intval($tenantId)));

这是我使用 $query->getDql() 时的结果:

FROM MstFont msf WHERE (full_font_name LIKE ? OR
                full_font_name LIKE ? OR
                full_font_name LIKE ? OR
                full_font_name = ? OR
                font_name = ?) AND ((tenant_id = 0 OR tenant_id = ?))

这是我使用 $query->getSqlQuery() 时的结果:

SELECT m.font_id AS m__font_id, m.tenant_id AS m__tenant_id, m.font_name AS m__font_name, m.font_file AS m__font_file, m.font_category AS m__font_category, m.vendor AS m__vendor, m.full_font_name AS m__full_font_name, m.font_name_ap AS m__font_name_ap FROM mst_font m WHERE (m.full_font_name LIKE ? OR
                full_font_name LIKE ? OR
                full_font_name LIKE ? OR
                full_font_name = ? OR
                font_name = ? AND (m.tenant_id = 0 OR m.tenant_id = ?))

有没有人帮我解释这个问题?

4

1 回答 1

0

尝试删除多余的括号,例如:

$query->andWhere('((tenant_id = 0 OR tenant_id = ?))', array(intval($tenantId)));

$query->andWhere('tenant_id = 0 OR tenant_id = ?', array(intval($tenantId)));

对第一个也做同样的事情,比如:

$query->where('(full_font_name LIKE ? OR ...

$query->where('full_font_name LIKE ? OR ...

看看会发生什么。你不需要它们,Doctrine 会为这些和/或条件加上括号。

于 2012-11-23T18:30:57.227 回答