简体   繁体   中英

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:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM