how to sort an entity's arrayCollection in symfony2

后端 未结 4 1722
借酒劲吻你
借酒劲吻你 2021-02-01 15:33

I have an entity \"container\" with this property

/**
 * @ORM\\OneToMany(targetEntity=\"BizTV\\ContentManagementBundle\\Entity\\Content\", mappedBy=\"container\"         


        
4条回答
  •  粉色の甜心
    2021-02-01 16:12

    If you want to be sure that you always get your relations in the order based on current property values, you can do something like this:

    $sort = new Criteria(null, ['Order' => Criteria::ASC]);
    return $this->yourCollectionProperty->matching($sort);
    

    Use that for example if you've changed the Order property. Works great for a "Last modified date" as well.

提交回复
热议问题