How to order by multiple columns with propel

Radu Dragomir picture Radu Dragomir · Jan 3, 2011 · Viewed 9.8k times · Source

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

i tried:

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

but the second call to addAscendingOrderByColumn overrides the first one.

Regards, Radu.

Answer

macgyver picture macgyver · Dec 18, 2011

I was struggling with this issue and after reading this post I have been almost gave up... but suddendly I found this solution:

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

In this way the second call to addAscendingOrderByColumn will add the order to the first one.