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.

How can I make a free query by PHQL?

I have a query that uses multiple INNER JOIN's and relationships between external tables. I tried with the Resultset\Simple, but it depends on a lot of models.

edited May '16

PHQL is query language ONLY for models. You can ust just plain PHQL or queryBuilder. But if you need to operate on table names, not model names then you can only use raw sql.

But for your problem you can use just modelsManageR(queryBuilder) i guess.

QueryBuilder unfortunately does not work for me. I think my question was poorly worded, but what I want is to use some PHALCON tool to perform a query pure form, ie, as it is written.

edited May '16

Why does not work ? What exactly you want achieve ? So you just want to perform sql query etc without models ? Then access db service and make same query. But i would really recommend querybuilder, in most cases it's pretty much enough(until we gonna use unions). Don't know why you want to use mvc framework if you don't gonna have models and want to use raw queries.

edited May '16

Each has their case and their needs. I'm migrating a system that was developed in CodeIgniter for Phalcon. In it there is a module where you work with the ERP tables of the company (legacy system, old but very necessary for the company) to make apportionments between various questions. It is entirely unnecessary to make models for these tables, since they are only for reference. So I need to run some queries (not all) in raw SQL. Can you help me?


Just access db service from di and do whatever you want as raw query -

Thank you. I'll try.

edited May '16

That was it. Thanks.

It works for both MySql and for Oracle.

No problem, but still o would recommend to create models, if you only need to make this one query then it's fine but in other cases you should use models really.

The raw queries are for this module. The rest of the system is supported by models.

To get an idea of the queries has a INNER JOIN with a view as the main table in addition to making several JOINs with ERP tables by linking them to DBLINKs with specific moorings. Infeasible create models to meet this need since it is only for reference and not insertion and data change.