Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.2.1
-
Fix Version/s: None
-
Component/s: Query
-
Labels:None
Description
$limit = 10;
$q = 'Me';
$field = 'contractor';
$q = Doctrine_Query::create()
->select(sprintf('DISTINCT PublicContract.%s', $field))
->from('PublicContract')
->where(sprintf('PublicContract.%s LIKE ?', $field), sprintf('%%%s%%', $q))
->limit($limit);
The QUERY is WRONG:
// SELECT DISTINCT p.id AS p_id, p.contractor AS p_contractor FROM public_contract p WHERE (p.contractor LIKE ?) LIMIT 10 - (%Me%)
I can simply GROUP BY the contractor field, because DISTINCT can be considered as a special case of GROUP BY - and have the results I want:
$q = Doctrine_Query::create()
->select(sprintf('PublicContract.%s', $field))
->from('PublicContract')
->where(sprintf('PublicContract.%s LIKE ?', $field), sprintf('%%%s%%', $q))
->groupBy(sprintf('PublicContract.%s', $field))
->limit($limit);
Test case or patch?