I have a Product admin class. The Product entity has a many-to-one relationship with a Category entity, i.e. a product is associated with a category.
In the admin \"list
It seems a workaround, but it works. You have to add a join overriding createQuery() method, than assign a default sortBy overriding $datagridValues:
1,
'_sort_order' => 'ASC', // sort direction
'_sort_by' => 'c.name' // field name
);
/**
* @return \Sonata\AdminBundle\Datagrid\ProxyQueryInterface
*/
public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
return new ProxyQuery($query
->join(sprintf('%s.category', $query->getRootAlias()), 'c'));
}
}