I've been wrestling with this problem for a while now and can't see how to go about it. I have 2 dataobjects (Project, Enhancement). Project has many Enhancements, Enhancement has one Project.
I was using the ProjectsID column in Enhancements to get Enhancements that haven't been assigned to a project. I also only want to get enhancements that are at certain status levels (I don't want completed enhancements to show in the list)
$enhancements = new DataObjectSet();
$enhancements->merge(DataObject::get('Enhancement', "StatusLevelsID = 1 AND ProjectsID = 0")); // Approved
$enhancements->merge(DataObject::get('Enhancement', "StatusLevelsID = 4 AND ProjectsID = 0")); // In Progress
if ($enhancements) {
$map = $enhancements->toDropdownMap('ID', 'Title');
}
$fields->addFieldToTab("Root.ProjectEnhancements", new AsmselectField('Enhances', 'Enhancement', $map));
This was working great until I realized that if I delete a project, there will be enhancements with a ProjectsID equal to a deleted Project ID and I won't be able to add them to another project.
So instead of just getting ProjectsID = 0, I need to get ProjectsID that don't match an existing ID for my Project class. I'm not sure how to find these.
Brian