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

Exception when using QueryBuilder & Pagination

I'm building a query with QueryBuilder, then using it as the data source for the Paginator, like so

$Builder = $this->modelsManager->createBuilder()
                                ->from('\OB\Model\Request')
                                ->orderBy('entered_date');

$Paginator = new \Phalcon\Paginator\Adapter\QueryBuilder([
            "builder"=>$Builder,
            "limit"=>$this->config->pagination,
            "page"=>$page
        ]);

The exception being raised is:

Can't obtain the model 'entered_date' source from the _models list, when preparing: SELECT [\OB\Model\Request].* FROM [\OB\Model\Request] ORDER BY entered_date LIMIT 2

When I remove the ->orderBy("entered_date") clause, everything works fine. I know entered_date is an actual property of the \OB\Model\Request class because I can output it in my view. In fact, this exception gets raised regardless of the field name I order by.

Any idea what this exception means?



98.9k
Accepted
answer

Removing the \ from from('\OB\Model\Request') does help?

Yep, that fixed it. But wow - that's an obscure fix. Why doesn't the ORM remove leading slashes?