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 not found when using QueryBuilder

I'm using QueryBuilder for my pagination. First I have to create the Builder, and I do so with this:

$Builder = $this->modelsManager->createBuilder()
    ->from('\Pay\Model\Transaction')
    ->orderBy('id DESC');

However, when I do that I get this error:

Phalcon Exception: Column 'id' doesn't belong to any of the selected models (2), when preparing: SELECT [\Pay\Model\Transaction].* FROM [\Pay\Model\Transaction] ORDER BY id DESC LIMIT 10

When I remove that orderBy() clause, everything works fine. I can then output all my Transactions - even the "id" of each Transaction. Am I missing some way of specifying the columns available to Transaction?

Edit: The problem was the leading slash in "\Pay\Model\Transaction". While it is valid PHP syntax, PHQL must parse it differently.



2.5k
Accepted
answer
edited Jul '14

Hi quasipickle! Error code

->from('\Pay\Model\Transaction')

You must change \ in: "'\Pay" => "Pay"

Thanks!