Php 排序带有OrderBy注释的ArrayCollection问题
我试图从检索到的实体中按特定顺序对ArrayCollection进行排序,但@ORM\OrderBy不会触发 Showcase.php:Php 排序带有OrderBy注释的ArrayCollection问题,php,symfony,doctrine-orm,one-to-many,arraycollection,Php,Symfony,Doctrine Orm,One To Many,Arraycollection,我试图从检索到的实体中按特定顺序对ArrayCollection进行排序,但@ORM\OrderBy不会触发 Showcase.php: /*...*/ use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; /** @ORM\Entity **/ class Showcase { /*...*/ /** @ORM\OneToMany(targetEntity="Showc
/*...*/
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/** @ORM\Entity **/
class Showcase
{
/*...*/
/** @ORM\OneToMany(targetEntity="ShowcaseGelato", mappedBy="showcase", fetch="EAGER")
* @ORM\OrderBy({"position" = "ASC"}) **/
private $gelatos;
public function __construct()
{
$this->gelatos = new ArrayCollection();
}
/*...*/
ShowcaseGelato.php:
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class ShowcaseGelato
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Gelato", fetch="EAGER")
*/
private $gelato;
/**
* @ORM\ManyToOne(targetEntity="Showcase", inversedBy="gelatos")
* @ORM\JoinColumn(name="showcase_id", referencedColumnName="id")
*/
private $showcase;
/**
* @ORM\Column(name="position", type="integer")
*/
private $position;
ShowcaseController.php:
/*...*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$showcase = $em->getRepository('TodaysGelatoBundle:Showcase')->find(1);
return $this->render(
'TodaysGelatoBundle:Showcase:index.html.twig', array(
'showcase' => $showcase,
)
);
}
结果是:
我错过了什么?任何帮助都将不胜感激
数据库项目视图:你能在没有getter和setter的情况下给出完整的展示吗?@Franky238:更新你也可以查看我的存储库:我能给你什么建议:尝试转储sql在你的数据库上做什么。我看不见mistake@TomaszSzymanek我建议在@Franky238上报告这一点:我按照你的话做了,ArrayCollection顺序保持不变。我想我会按照威尔特的建议来报告。