Jump to:

7938 Posts in 1541 Topics by 945 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » has_one relation in DataObjectManager

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 2975 Views
  • timwjohn
    Community Member
    98 Posts

    Re: has_one relation in DataObjectManager Link to this post

    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(
    'CategoryName' => 'Category Name',
    'Sector.Name' => 'Sector Name'
    '',// source filter
    '',// source sort
    'LEFT JOIN `sector` ON `sector`.`ID` = `category`.`sectorID`'
    $sectors = DataObject::get('Sector');
    'Filter by Sector',
    isset($sectors) ? $sectors->toDropDownMap('Name', 'Name') : array()
    $category_manager->setPermissions(array('only_related')); // add, edit, show, delete, only_related

    $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?

Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.