How to order multiple columns using

I need to sort a query by 2 columns. Is propel possible?

I tried:

$c->addAscendingOrderByColumn(self::COL1);
$c->addAscendingOrderByColumn(self::COL2);

but the second call to addAscendingOrderByColumn overrides the first.

Regards, Radu.

+3
source share
2 answers

Unfortunately, if you are using Propel 1.4 (Symfony 1.4), it seems you will have to switch to raw SQL there ...

There is no answer on the forum (old) Symfony: http://oldforum.symfony-project.org/index.php/m/90447/

However, since Propel 1.5 should work with the new syntax (Doctrine style). It is not described in detail in the Propel document, but when I check this, it works (gives ORDER BY author.name ASC, author.id DESC).

$authors = AuthorQuery::create()
  ->orderByName()
  ->orderById('desc')
  ->find();

Perhaps consider upgrading to Propel 1.5.

+5

, , , ... , , :

$criteria->addAscendingOrderByColumn(ClassPeer::COLUMN1)->addAscendingOrderByColumn(ClassPeer::COLUMN2);

, addAscendingOrderByColumn .

+5

Source: https://habr.com/ru/post/1783213/


All Articles