4

I can't make to work a entity sorting in the sonata admin listing, here is my entity:

class User extends BaseUser {
/**
* @ORM\ManyToOne(targetEntity="Region", inversedBy="users")
*/
protected $preferredRegion;
}

And here is the configureListFields definition:

 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")

How can I make this sort to work for the entity so it sorts alphabetically by my entity name?

Thank you

Julian Mancera

4

1 回答 1

4

尝试:

$listMapper->add('preferredRegion.id', NULL, array('label' => 'Preferred Region'));

如果可行,您可以在该表中放置其他列的 .title、.name 而不是 .id。

于 2012-11-23T18:38:48.223 回答