Propel2 ORM:如何按字段实现

时间:2014-05-21 11:53:55

标签: orm sql-order-by propel

我在我的php webapplication中使用Propel 2 ORM,在某个查询中我喜欢按字段排序我的结果。

$orderedIdArray = array(20, 10, 15, 30);
MyClassQuery::create()
    ->filterById($orderedIdArray, Criteria::IN)
    //->orderByField("Id", $orderedIdArray) --> method does not exist in Propel
    ->find();

我通过Propel Criteria for Peer Class在线找到了解决方案。 http://shout.setfive.com/2009/10/13/adding-order-by-field-to-propel-criterias/

但是我想用我的Query Class做这个。您将如何在Query Class中实现该方法?

1 个答案:

答案 0 :(得分:1)

您只需将addOrderByField的代码复制并粘贴到MyClassQuery课程中即可正常使用。在Propel 2中没有必要使用sfCriteria