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

first argument in constructor of Resultset\Complex - how to built raw SQL

I am trying to build a query using raw SQL. I want the query to be returned as complex Resultset, how to do it?


use use Phalcon\Mvc\Model\Resultset\Complex as Resultset;

$rowSql = 'SELECT
          DISTINCT i.car_id
          FROM cars AS i
          LEFT JOIN
            (some sql..)
          AS e ON (e.car_id = i.car_id)
          WHERE
          i.source_id = 2
          AND e.car IS NULL LIMIT 180;';

$model = new Cars();

$result = new Resultset([
            'HOW THIS ARRAY SHOULD LOOK LIKE?',
        ], $model->getReadConnection()->query($rowSql));

I don't know how first argument of Resultset\Complex constructor should look like? It's array $columnTypes.

TIA!



34.6k
Accepted
answer

You don't have to use Resultset\Complex but Resultset\Simple: https://docs.phalcon.io/en/latest/reference/phql.html#using-raw-sql