我想了解基于相关实体订购Doctrine Collection的最佳方法.在这种情况下,无法使用@orderBy注释.
我在互联网上找到了5个解决方案.
1)向AbstractEntity添加方法(根据Ian Belter /sf/answers/1552846921/)
/**
* This method will change the order of elements within a Collection based on the given method.
* It preserves array keys to avoid any direct access issues but will order the elements
* within the array so that iteration will be done in the requested order.
*
* @param string $property
* @param array $calledMethods
*
* @return $this
* @throws \InvalidArgumentException
*/
public function orderCollection($property, $calledMethods = array())
{
/** …Run Code Online (Sandbox Code Playgroud) 我的问题接近这个问题,但并不完全适合我的问题.
我在一个实体中有这个专栏:
/**
* @var ArrayCollection[SubjectTag]
*
* @ORM\OneToMany(targetEntity="SubjectTag", mappedBy="subject")
* @Assert\Count(max = 10, maxMessage = "You can't create more than 10 tags.")
* @Assert\Valid()
*/
protected $subjectTags;
Run Code Online (Sandbox Code Playgroud)
我想通过定义的位置动态地对我的标签进行排序SubjectTag.position.