我想了解基于相关实体订购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)