Questions? Forum: https://phalcon.io/forum or Discord: https://phalcon.io/discord
Describe the bug
Models manager gets a query with the NOT BETWEEN operation in the WHERE clause, it converts the operator to BETWEEN NOT and receives an error on execution.
The issue stems from \Phalcon\Mvc\Model\Query::getExpression(). It resolves the operator to BETWEEN NOT at phalcon/Mvc/Model/Query.zep#L2063-L2069
To Reproduce
- Create a table with a field compatible with the
BETWEEN operator
- Write a query with a
NOT BETWEEN operator in the WHERE clause
- Execute the query through the
\Phalcon\Mvc\Model\Manager service
- Check the final query that's been executed and see the switch to
BETWEEN NOT
$q = 'SELECT created_at FROM [Models\Orders] WHERE created_at NOT BETWEEN "2025-10-02 00:00:00" AND "2025-10-02 23:59:59"';
try {
$this->modelsManager->executeQuery($q);
} catch (Exception $e) {
$sql = $this->db->getSQLStatement();
}
The variable $sql now has the operator changed to BETWEEN NOT
Expected behavior
The operator should remain as NOT BETWEEN, BETWEEN NOT is not a valid usage and fails the execution.
Details
- Phalcon version: 4.x, 5.x
- PHP Version: 7.x, 8.x
- Server: Nginx
Questions? Forum: https://phalcon.io/forum or Discord: https://phalcon.io/discord
Describe the bug
Models manager gets a query with the
NOT BETWEENoperation in theWHEREclause, it converts the operator toBETWEEN NOTand receives an error on execution.The issue stems from
\Phalcon\Mvc\Model\Query::getExpression(). It resolves the operator toBETWEEN NOTat phalcon/Mvc/Model/Query.zep#L2063-L2069To Reproduce
BETWEENoperatorNOT BETWEENoperator in theWHEREclause\Phalcon\Mvc\Model\ManagerserviceBETWEEN NOTThe variable
$sqlnow has the operator changed toBETWEEN NOTExpected behavior
The operator should remain as
NOT BETWEEN,BETWEEN NOTis not a valid usage and fails the execution.Details