We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

"Column name doesn't belong to any of the selected models" - column begins with "not"

I've been working through changes required to get our app upgraded from v3.4 to v4 and hit an issue this morning due to a column name in one of our tables being called notification_sent. When I use the ::count() method on the model and send a condition of notification_sent = 1 I get the following error:

Column 'ification_sent' doesn't belong to any of the selected models (1), when preparing...

It appears that the ORM is splitting the column name up, thinking the initial "not" is part of the SQL?

I've fixed this by wrapping the column name in quotations but I'm concerned because we have a bunch of tables all prefixed with notification_ and I don't know how the ORM will behave with them.

This wasn't a problem on v3.4 and the docs don't show the need to wrap column names in quotes, so I'm thinking this may be a bug.

I'm happy to open an Issue on Github but wanted to see if others had the same problem and if it could genuinely be a bug?


  • Phalcon v4.0.6
  • PHP v7.4.11
  • Ubuntu v20.04.1
  • MySQL v8.0.21-0ubuntu0.20.04.4

This sounds like a bug to me.

Hmm, I'm not having much luck with this either... Perhaps I've not setup the SQL server properly? Although it does find the database so I'm not too sure why it wouldn't find the table. This is the error I get when using the above:

Column 'name' doesn't belong to any of the selected models (1), when preparing: SELECT [TkcApi\Models\Customers].* FROM [TkcApi\Models\Customers] ORDER BY name ASC LIMIT :AP0:

0 [internal function]: Phalcon\Mvc\Model\Query->_getQualified(Array)

1 [internal function]: Phalcon\Mvc\Model\Query->_getExpression(Array)

2 [internal function]: Phalcon\Mvc\Model\Query->_getOrderClause(Array)

3 [internal function]: Phalcon\Mvc\Model\Query->_prepareSelect()

4 [internal function]: Phalcon\Mvc\Model\Query->parse()

5 [internal function]: Phalcon\Mvc\Model\Query->execute()

6 /Users/danieldoyle/Projects/tkc-api/public_html/controllers/CustomersController.php(17): Phalcon\Mvc\Model::find(Array)

7 [internal function]: TkcApi\Controllers\CustomersController->index()

8 [internal function]: Phalcon\Mvc\Micro\LazyLoader->__call('index', Array)

9 [internal function]: Phalcon\Mvc\Micro\LazyLoader->index()

10 /Users/danieldoyle/Projects/tkc-api/public_html/index.php(23): Phalcon\Mvc\Micro->handle()

11 {main}**

I guess you're not using namespaces though. Hmm