Jump to:

7939 Posts in 1472 Topics by 944 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: 2827 Views
  • timwjohn
    Avatar
    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(
    $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?

    2827 Views
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.