How to order by multiple columns with propel

大城市里の小女人 提交于 2019-12-10 20:32:43

问题


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.


回答1:


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

No answer in the (old) Symfony forum : http://oldforum.symfony-project.org/index.php/m/90447/

However, since Propel 1.5 it should work with the new syntax (Doctrine style). It's not detailed in Propel doc but when I test this, it works (gives ORDER BY author.name ASC, author.id DESC).

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

Maybe consider upgrading to Propel 1.5.




回答2:


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.



来源:https://stackoverflow.com/questions/4584484/how-to-order-by-multiple-columns-with-propel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!