Ok, I now pass an empty array to setFilter() if no results are returned.
The alises thing - definitely what I would do were I dealing with raw SQL. Is there a way of doing this when instantiating DOM? This is my code. Having a Name field in both Category and Sector was causing Sector.Name to appear in both columns:
function getCMSFields()
{
$fields = parent::getCMSFields();
$category_manager = new ManyManyDataObjectManager(
$this,
'Categories',
'Category',
array(
'CategoryName' => 'Category Name',
'Sector.Name' => 'Sector Name'
),
'getCMSFields_forPopup',
'',// source filter
'',// source sort
'LEFT JOIN `sector` ON `sector`.`ID` = `category`.`sectorID`'
);
$sectors = DataObject::get('Sector');
$category_manager->setFilter(
'Sector.Name',
'Filter by Sector',
isset($sectors) ? $sectors->toDropDownMap('Name', 'Name') : array()
);
$category_manager->setPermissions(array('only_related')); // add, edit, show, delete, only_related
$category_manager->setPluralTitle('Categories');
$category_manager->setUseViewAll(true);
$category_manager->setPerPageMap(array(9999));
$category_manager->setPageSize(9999);
$fields->replaceField('Categories', $category_manager);
return $fields;
}
(Sorry - it seems my code isn't displaying properly in code view, even though I've converted tabs to spaces..)
Would I be able to set an alias here without passing a custom SQL query to DOM?