Skip to content

[BUG]: \Phalcon\Mvc\Model\Manager converts NOT BETWEEN operator to BETWEEN NOT #16812

@toramanlis

Description

@toramanlis

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

Metadata

Metadata

Assignees

Labels

5.0The issues we want to solve in the 5.0 releasebugA bug reportexternal dependencyThis issue depends on external issue to be resolved.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions