如何使用 propel 按多列排序
我需要按 2 列对查询进行排序。使用推进可以实现这一点吗?
我尝试过:
$c->addAscendingOrderByColumn(self::COL1);
$c->addAscendingOrderByColumn(self::COL2);
但对 addAscendingOrderByColumn 的第二次调用会覆盖第一个调用。
问候, 拉杜。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我一直在努力解决这个问题,读完这篇文章后我几乎放弃了......但突然我找到了这个解决方案:
这样,第二次调用 addAscendingOrderByColumn 会将订单添加到第一个调用。
I was struggling with this issue and after reading this post I have been almost gave up... but suddendly I found this solution:
In this way the second call to addAscendingOrderByColumn will add the order to the first one.
不幸的是,如果您使用 Propel 1.4 (Symfony 1.4),似乎您必须切换到原始 SQL...
(旧)Symfony 论坛中没有答案:http://oldforum.symfony-project.org/index.php/m/90447/
但是,从 Propel 1.5 开始应该使用新的语法(Doctrine 风格)。 Propel 文档中没有详细说明,但当我测试它时,它有效(给出
ORDER BYauthor.name ASC,author.id DESC
)。也许考虑升级到 Propel 1.5。
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
).Maybe consider upgrading to Propel 1.5.