Doctrine模型的默认排序属性 [英] Default sort attribute for Doctrine Model

查看:129
本文介绍了Doctrine模型的默认排序属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有办法声明我的教义模式的默认顺序。

I was wondering if there is a way to declare the default order for my doctrine models.

例如

我有一个工作模型,它有照片。加载作品时,与其相关联的所有照片将被加载到 $ work->照片中。当我们显示它们时,它们被按照它们的ID排序。

I have a work model and it has photos. When I load a work, all photos associated to it get loaded into $work->photos. When I display them, they are ordered by their IDs.

在另一个字段上声明默认顺序或者可能会覆盖提取行为,这将非常方便。

It would be very convenient to declare a default order on another field or perhaps override the fetch behaviour altoghether.

我宁愿不把照片转换成一个数组并使用usort。谢谢。

I'd rather not to convert the photos to an array and use usort. Thanks.

推荐答案

您可以在YAML中指定如下:

You can specify it in the YAML as follows:

如果是表中的字段的排序顺序,则添加:

If it's a sorting order for a field in the table itself add:

options:
  orderBy: fieldname

其中选项:的深度与您将有一个列:关系:条目。注意: orderBy的大小写:至关重要;错误,你会得到没有错误,但也没有排序。

where options: is at the same depth as you'd have a columns: or relations: entry. NB: The capitalisation of orderBy: is vital; get it wrong and you'll get no error but also no sorting.

如果它是关系的排序顺序,那么在关系中你可以跳过选项:部分,然后放入:

If it's a sorting order for a relationship then, within the relationship you can skip the options: part and just put in:

orderBy: fieldname

这篇关于Doctrine模型的默认排序属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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