我有以下问题。我有两个处于ManyToMany关系的实体,我想为它们排序某个关键字序列。
Team.php
/**
* @ORM\ManyToMany(targetEntity="Domain\Entity\Player")
* @ORM\JoinTable(name="match_substitute_player_home")
*/
public $substitutePlayersHome;
现在我要点这些来订购它
/**
* @ORM\ManyToMany(targetEntity="Domain\Entity\Player")
* @ORM\JoinTable(name="match_substitute_player_home")
* @ORM\OrderBy({"FIELD(type, {'keep','def','atk'})"})
*/
public $substitutePlayersHome;
我的问题是如何将OrderBy Annotation权限用于字符串值列表。
它必须是这样的一条线,但这条线不起作用:
* @ORM\OrderBy({"FIELD(type, {'keep','def','atk'})"})
我的测试来源:
- > http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/ordered-associations.html
- > Propel ORM: Order By FIELD
答案 0 :(得分:1)
默认情况下,在doctrine中未定义FIELD属性。下载并试用此插件。 https://github.com/beberlei/doctrineextensions
手动配置包:
doctrine:
orm:
dql:
string_functions:
field: DoctrineExtensions\Query\Mysql\Field