我的问题接近this one ,但与我的不完全吻合。
我在实体中有此列:
/**
* @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;
我想根据 SubjectTag.position
中定义的位置对我的标签进行动态排序。
最佳答案
尝试为 Ordering To-Many Associations 使用 doctrine2 ORM 功能像这样:
/**
* @var ArrayCollection[SubjectTag]
*
* @ORM\OneToMany(targetEntity="SubjectTag", mappedBy="subject")
* @ORM\OrderBy({"position" = "ASC"})
* @Assert\Count(max = 10, maxMessage = "You can't create more than 10 tags.")
* @Assert\Valid()
*/
protected $subjectTags;
希望对你有帮助
关于php - 对学说的@OneToMany ArrayCollection 进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27469222/