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

Ordering with Column alias

Hi All,

I'm having issue with sorting with column alias, e.g. (Please don't bother with uncomplete builder statement. I guess you should get the point)


        $builder = $this->modelsManager->createBuilder()
            ->columns(array('t.id', 'colalias' => 'COUNT(t.something)'))
            ->groupBy('t.id')
            ->orderBy('colalias DESC');

This throwed Scanning error as the order clause translated into [colalias DESC]. I guess it should be [colalias] DESC. Did I miss something or is this a bug with phalcon 2.0.8?

FYI, orderBy without stating ASC/DESC work just fine:

            ->orderBy('colalias');

Thanks in advance.



58.4k
edited Oct '15

Hi man

You try replace the oderby above

To

            ->orderBy('colalias+asc');


2.1k
edited Oct '15

Thien,

No, the plus sign didn't work

Seeing link, I think it's not supported yet.

How to contribute btw?

Right now I'm working around with the unaliased statement.

edit: created issue #11052 on github



58.4k

Hi

I don't know why this not work with you, the my code I have use

        if (!empty($this->gridFilters[$filterKey]['order'])) {
            $builder->orderBy($this->gridFilters[$filterKey]['order']); // ex: title asc
        }

See more https://github.com/phanbook/phanbook/blob/master/core/modules/backend/controllers/ControllerBase.php#L570