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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Problem storing multiple items from a DataObject


Reply


399 Views

Avatar
woodb2

Community Member, 48 Posts

3 July 2012 at 5:00am

I have a couple of DataObjects. The main one is called Enhancement (for storing enhancement requests). Enhancement has a $has_one to $has_many to a dataobject StatusLevels (just an object where the users can manage the different status levels that enhancements can be. This all works great (using modeladmin for everything).

The problem occurs with my Project dataobject. I want to be able to assign multiple enhancements to a project. I've tried using DataObjectManager, AsmselectField and ItemSelectFied, but each has it's drawbacks and none of them work how I need.

AsmselectField is my favorite, but here's what's happening:

I'm creating a dropdownfield with the title from Enhancement. I can get this to work, but I only want enhancements that statuslevel isn't completed. I can add enhancements, but soon as I change their status in the Enhancement Object to completed, they no longer appear in my pulldown (which is exactly like I want), but any ones already select are removed from my list. It filters out the completed ones from my asmselect field list. Which I don't want it to do.

   $enhancements = DataObject::get('Enhancement', 'StatusLevelsID != 2');
   if ($enhancements) {
      $map = $enhancements->toDropdownMap('ID', 'Title');
   }
   $fields->addFieldToTab("Root.ProjectEnhancements", new AsmselectField('Enhancements', 'Enhancement', $map));

This field would working great if I showed every enhancement in the list, but I really want to filter it out so that you can't select enhancements that are already completed. Is there a way to not have it filter out the selected list too?

Brian