23376 Posts in 18218 Topics by 2867 members
|Go to End|
10 February 2012 at 3:43am
I currently have 2 Dataobjects, "Classroom" and "Students". In Classroom, I currently have a working CheckboxsetField that lets me add students to it by getting the names of the students from the Students Dataobject:
$studentlist = DataObject::get("Students");
$mapstudents = $studentlist ? $mapstudents = $studentlist->toDropdownMap('ID','Title') : array();
$fields->addFieldToTab('Root.Main', new CheckboxsetField('App','Apps', $mapstudents));
Since I have a 1:n relation established, each student can only be in 1 classroom (which is what I want). The problem is the CheckboxsetField always shows every student. If I create a new classroom record and select a student that was already in another class, that student is moved to the new record and remove from the previous class.
What I want to happen is the Checkboxset to only show students that haven't been assigned to a classroom.
Any help would be appreciated,
10 February 2012 at 1:49pm Last edited: 10 February 2012 1:50pm
If you set uo Student to have
static $has_one= array('Classroom' => 'Classroom');
You could do something like
DataObject::get('Student', 'ClassroomID' = '0' or is null 'ClassroomID');
11 February 2012 at 2:35am
Thanks, worked perfectly! I need to get in the practice of looking at the tables a little more ( phpmyadmin or DBplumber). I forgot about the classroomID column being created because of the $has_one. I didn't realize that I had something I could filter on that easily. Thanks again!!
|Go to Top|