gpt4 book ai didi

php - 对学说的@OneToMany ArrayCollection 进行排序

转载 作者:可可西里 更新时间:2023-11-01 13:53:56 26 4
gpt4 key购买 nike

我的问题接近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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com