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

How to get unique alias when using more tables in phalcon getSQL() function

I have two tables, and both have 'id' attribute, but return of the getSQL() function looks like this: 'SELECT car.id AS id, car.color AS color, car.seat AS seat, person.name AS name, person.age AS age... <- I'm missing here the person's 'id'.

Is there any option for the getSQL() function, that solves this problem and at each 'id' collision it will get a unique alias name? (e.g. : 'tablename_id')

How are you building that query? Using the query builder?

edited Jul '15

like this:

    $query = $this->modelsManager->createQuery($filter->conditions);

    $count = $this->db->fetchAll(
        "SELECT COUNT(*) as count FROM(" . $query->getSQL()['sql'] . ") AS Filtered",
        \Phalcon\Db::FETCH_ASSOC,
        $filter->bind
    );

How are you building that query? Using the query builder?