[英]Sonata admin - “order by” does't work for Entity
I can't make to work a entity sorting in the sonata admin listing, here is my entity: 我无法在sonata admin列表中进行实体排序,这是我的实体:
class User extends BaseUser {
/**
* @ORM\ManyToOne(targetEntity="Region", inversedBy="users")
*/
protected $preferredRegion;
}
And here is the configureListFields definition: 这是configureListFields定义:
protected function configureListFields(ListMapper $listMapper) {
$listMapper->add('preferredRegion', NULL, array('label' => 'Preferred Region', 'sortable' => 'preferredRegion'))
}
When clicking on the table head column to sort it by my entity name I get this error: 单击表头列以按实体名称对其进行排序时出现此错误:
An exception has been thrown during the rendering of a template ("[Semantical Error] line 0, col 25 near 'AS __order_by': Error: Entity\\User has no field or association named AS") 在渲染模板期间抛出了异常(“[语义错误]第0行,第25行附近'AS __order_by':错误:实体\\用户没有名为AS的字段或关联”)
How can I make this sort to work for the entity so it sorts alphabetically by my entity name? 如何使这种类型适用于实体,以便按实体名称的字母顺序排序?
Thank you 谢谢
Julian Mancera 朱利安·曼斯拉
Try: 尝试:
$listMapper->add('preferredRegion.id', NULL, array('label' => 'Preferred Region'));
If that works, instead of .id you can put .title, .name of some other column in that table. 如果这样做,而不是.id,你可以把该表中其他列的.title,.name。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.