To sort on foreign keys in admin generator, you need to overload the processSort function by defining the sorting column in the foreign table like this in actions.class.php :
protected function processSort()
{
parent::processSort();
if ($sort_column = $this->getUser()->getAttribute('sort', null, 'sf_admin/stat/sort'))
{
if ($sort_column === 'person_id')
{
$this->getUser()->setAttribute('sort', 'last_name', 'sf_admin/stat/sort');
}
}
}
You need also to overload the addSortCriteria function like this :
protected function addSortCriteria(&$c)
{
parent::addSortCriteria($c);
if ($sort_column = $this->getUser()->getAttribute('sort', null, 'sf_admin/stat/sort'))
{
if ($sort_column === 'last_name')
{
$this->getUser()->setAttribute('sort', 'person_id', 'sf_admin/stat/sort');
}
}
}
This method works this v0.6.3 but not after.
With a newer version, the solution seems to pass an array instead of 'last_name' (second parameter) to setAttribute, array containing the table and column name, but we need to change the behaviour of the generated translateFieldName function in the Peer class.