Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.



1.0k
Accepted
answer
edited Jul '14

Hi quasipickle! Error code

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

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

Thanks!