如何使用推进器按多列排序 [英] How to order by multiple columns with propel

查看:49
本文介绍了如何使用推进器按多列排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要按 2 列对查询进行排序.这可以使用 propel 吗?

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

我试过:

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

但是第二次调用 addAscendingOrderByColumn 会覆盖第一次调用.

but the second call to addAscendingOrderByColumn overrides the first one.

问候,拉杜.

推荐答案

不幸的是,如果您使用的是 Propel 1.4 (Symfony 1.4),似乎您将不得不在那里切换到原始 SQL...

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

在(旧)Symfony 论坛中没有答案:http://oldforum.symfony-project.org/index.php/m/90447/

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

然而,从 Propel 1.5 开始,它应该使用新的语法(Doctrine 风格).Propel 文档中没有详细说明,但是当我测试它时,它可以工作(给出 ORDER BY author.name ASC, author.id DESC).

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();

也许可以考虑升级到 Propel 1.5.

Maybe consider upgrading to Propel 1.5.

这篇关于如何使用推进器按多列排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆