I'm getting an error when trying to use a column alias in the having clause. Am I doing something wrong or this is not supported?
$query = $this->modelsManager->createBuilder()
->addFrom('Iwerp\Models\Products', 'Products')
->columns([
'productId' => 'Products.id',
'requiredQuantity' => 'SUM(Products.quantity)',
])
->groupBy('Products.id')
->having('requiredQuantity > 0');
$paginator = new PaginatorQueryBuilder([
'builder' => $query,
'limit' => $limit,
'page' => (int) (floor($start / $length) + 1),
]);
Column 'requiredQuantity' doesn't belong to any of the selected models (1), when preparing:
[....]
#0 [internal function]: Phalcon\Mvc\Model\Query->_getQualified(Array)
#1 [internal function]: Phalcon\Mvc\Model\Query->_getExpression(Array, true)
#2 [internal function]: Phalcon\Mvc\Model\Query->_getExpression(Array)
#3 [internal function]: Phalcon\Mvc\Model\Query->_prepareSelect()
#4 [internal function]: Phalcon\Mvc\Model\Query->parse()
#5 [internal function]: Phalcon\Mvc\Model\Query->getSql()
This is a simple example, but in my case I have a subquery instead of SUM(Products.quantity) and I would like to not repeat it in the having.