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

Problem with table columns with underscore

Hello!

I'm trying to execute a SQL query:

    $query = $this->modelsManager->createQuery('SELECT Usuarios.xid, Usuarios.email, UsuariosInfo.num_doc FROM Usuarios, UsuariosInfo');
    $users  = $query->execute();
    $this->view->usrs = new StdClass;
    $this->view->usrs = $users;

But I got this error:

Column 'num_doc' doesn't belong to the model or alias 'UsuariosInfo', when executing: SELECT Usuarios.xid, Usuarios.email, UsuariosInfo.num_doc FROM Usuarios, UsuariosInfo

I have tried CamelCase:

$query = $this->modelsManager->createQuery('SELECT Usuarios.xid, Usuarios.email, UsuariosInfo.NumDoc FROM Usuarios, UsuariosInfo');

But it doesn't work. What am I am doing wrong?



13.9k

By the way, num_doc is a new column on my table. I have used the webtools to re-generate ALL models based on ALL tables. But I don't know why something is not updated.

I noticed this because another column with underscore works!



13.9k
Accepted
answer

I apologyze, but I have deleted all files in /app/models/ and re-generate from scratch!

I realize that columnMap() function was not bee updated! That was the issue.

This ugly and radical action solved my problem, I will mark this comment as the "answer". If exist a best way to do it, please post it!

Thank you!