I created a DQL query with a complex having clause, such as:
->addSelect('((ACOS(SIN( ... AS miles') // Determines miles from lat/longs
->having('(r.location IS NULL) OR (miles <= r.location)');
The query works fine when executed by itself. However, when passed to Doctrine_Query::getCountSqlQuery(), it strips the r.location from the select fields, however this field remains in the having clause, and SQL errors out saying that it can't find the field. Then, when it is passed to Doctrine_Query::buildSqlQuery(true) by Doctrine_Pager->execute() (true designates to use getLimitSubquery()), getLimitSubquery() does the same thing and doesn't include these fields in the subquery.
I built a patch that I am using for my application to get around this. What it does is it searches for anything matching `[a-z0-9_]` in getCountSqlQuery() and getLimitSubquery() in the HAVING clause (for instance, would match `r`.`location`) and adds the field to the select query. This is a patch for Doctrine-1.2.1, and I haven't tested it extensively, so I'm not sure if it breaks anything, however in the quick testing I have done it seems to be working OK.
I greatly appreciate all the work the Doctrine team has done for this amazing ORM - keep up the good work! If I can be of any other assistance, please let me know.