如何按DESC一对一实体按Doctrine 2 ORM排序?
namespace Answer;
use Doctrine'ORM'Mapping as ORM;
class Answer {
...
/**
* @var Content
* @ORM'OneToOne(targetEntity="Answer'Content", mappedBy="answerswer")
* @ORM'OrderBy({"creationDate" = "DESC", "contentId" = "DESC"})
*/
protected $currentContent;
...
}
"OrderBy"注释仅适用于一对多和多对多关联。
你的问题中有答案。ORDER BY被应用于currentContent,但是如果你只有一个关联(所以与OneToOne),你只有一个currentContent的实体排序,所以ORDER BY是无效的。