7912 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » has_one relation in DataObjectManager
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | ||
| Author | Topic: | 2534 Views |
-
Re: has_one relation in DataObjectManager

24 March 2010 at 2:39am Last edited: 24 March 2010 3:51am
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?
| 2534 Views | ||
| Go to Top |

