默认的排序与注解主义模型 [英] Default sort for doctrine model with annotations

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

问题描述

在问题在默认排序属性教义型号一个 .yml 建议将定义一个默认的排序为一个集合值的关联。

In question at Default sort attribute for Doctrine Model a .yml is suggested to define a default sorting for a collection-valued association.

我想有我的模型由一个默认的排序进账,像下面这样:

I would like to have my models fetched by a default sorting, like following:

Foo:
    columns:
    ...
    options:
        orderBy: bar DESC

什么是诠释这相当于基于YAML的设置的?

What is the annotation equivalent of this YAML-based setup?

推荐答案

编辑:这是不可能的默认值。从仓库提取的实体是由提供的排序标准提取:

This is not possible with defaults. Entities fetched from repositories are fetched by the provided sorting criteria:

$entities = $entityRepository->findBy(array(), array('field' => 'ASC'));

这,<一个href=\"http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html\"相对=nofollow> DQL 和标准API 是获取当前方法与给定的排序标准的实体。

This, DQL and the Criteria API are the current ways of fetching entities with a given sorting criteria.

在什么问题默认排序属性教义型号是大约是集合值关联的排序,这无关与库实体直接抓取。

What the question at " Default sort attribute for Doctrine Model " is about is the sorting of collection-valued associations, which has nothing to do with direct fetching of entities from repositories.

对于那些协会,默认注释当量排序属性为原​​则型号< /一>是以下(原来的答案):

For those associations, the annotation-equivalent of " Default sort attribute for Doctrine Model " is following (original answer):

作为的<一个href=\"http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html#orderby\"相对=nofollow>教义2 ORM 官方说明文档,注释为A HREF =htt​​ps://github.com/doctrine/doctrine2/blob/2.3集合值关联默认的排序条件<。 2 / lib目录/教义/ ORM /映射/ OrderBy.php相对=nofollow> @OrderBy({场=ASC,otherField=DESC})

As of the official annotations documentation for Doctrine 2 ORM, the annotation for default sorting conditions of collection-valued associations @OrderBy({"field" = "ASC", "otherField" = "DESC"}).

下面是你将如何使用它:

Here's how you would use it:

/**
 * @ORM\OneToMany(targetEntity="Users")
 * @ORM\OrderBy({"username" = "ASC"})
 */
protected $users;

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

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