ZF2:如何在DB \ SQL中使用括号在mysql中进行分组?

时间:2013-09-06 11:03:05

标签: zend-framework2

我有以下代码:

$select = new Select();
$select->from($this->table);
$select->columns(array('id', 'refNumberOrder', 'dateOrder', 'kontragent', 'airOperator', 'aircraft', 'status'));

...

if ($object->customer != '') {
    $select->where->like('library_kontragent.short_name', $object->customer . '%');
}

if ($object->airOperator != '') {
    $select->where->like('library_air_operator.short_name', $object->airOperator . '%');
}

if ($object->aircraft != '') {
    $select->where->like('library_aircraft_type.name', $object->aircraft . '%');
}

$select->order('dateOrder ' . Select::ORDER_DESCENDING);
//\Zend\Debug\Debug::dump($select->getSqlString());

$resultSet = $this->selectWith($select);
$resultSet->buffer();

这就是下一行:

// MySQL result
WHERE "library_kontragent"."short_name" LIKE 'test%' 
    AND "library_air_operator"."short_name" LIKE 'test%' 
    AND "library_aircraft_type"."name" LIKE 'test%' 
ORDER BY "dateOrder" DESC"

我如何获得下一个字符串?

// MySQL result
WHERE ("library_kontragent"."short_name" LIKE 'test%' OR "library_kontragent"."long_name" LIKE 'test%') 
    AND "library_air_operator"."short_name" LIKE 'test%' 
    AND "library_aircraft_type"."name" LIKE 'test%' 
ORDER BY "dateOrder" DESC"

1 个答案:

答案 0 :(得分:3)

检查Ralph Schindler的this exampleNEST

中有UNNESTZend\Db\Sql\Where“运算符”