Reputation: 43
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
Upvotes: 4
Views: 1244
Reputation: 5158
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.
Upvotes: 4