public static function getAuctions($other = false)
{
$q = Doctrine::getTable('auctions')
->createQuery('u')
->select('TIMEDIFF(ends_at, NOW()) as time, ur.username as username, u.last_bider as last_bider,
pr.img_path as img_path, u.curr_price as price, pr.title as title, u.ends_at as ends_at,
ur.bids_left as bids_left')
->leftJoin('u.Products pr')
->leftJoin('u.sfGuardUser ur')
->where('u.ends_at > ?', date('Y-m-d H:i:s', time() - 5))
->andWhere('u.status = ?', 'Live');
***if($other == true)
$q->andWhere('time > ?', '01:00:00');***
$q->orderBy('time');
return $q->execute();
}
This query fails on the if clause, saying that mysql can’t find the time column. I did name it “time” above in the start.
If i use
if($other == true)
$q->andWhere('TIMEDIFF(ends_at, NOW()) > ?', '01:00:00');
it works, but I don’t want to repeat myself.
Any way to fix this (or is there a more practical way of building these condition based queries in doctrine?).
The select clause is executed AFTER the where clause so it is not possible to refer to a select clause defined alias in the where clause.
What can be done is to substitute the table with a subselect:
Don’t know if it is worth in your case.