Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

has_one relation in DataObjectManager


Go to End


9 Posts   3847 Views

Avatar
timwjohn

Community Member, 98 Posts

24 March 2010 at 2:39am

Edited: 24/03/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?

Go to Top