Hi,
As part of exercising tutorial-5, I have created Mentor and Student classes with one to many relation between Mentor to Student.
Every thing is working fine except that MyMentorID column in Student table always shows 0. It beleive it should store the ID of Mentor object which it beongs to. Is that correct? Any idea where the problem lies?
The code for Mentor and Student classes is shown below:
Mentor.php:
-------------
<?php
class Mentor extends Page {
public static $db = array(
'FirstName' => 'Text',
'LastName' => 'Text',
'Nationality' => 'Text'
);
static $has_many = array(
'Students' => 'Student'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab( 'Root.Content.Main', new TextField( 'FirstName', 'First Name' ) );
$fields->addFieldToTab( 'Root.Content.Main', new TextField( 'Lastname' ) );
$fields->addFieldToTab( 'Root.Content.Main', new TextField( 'Nationality' ) );
$tablefield = new HasManyComplexTableField(
$this,
'Students',
'Student',
array(
'FirstName' => 'FirstName',
'Lastname' => 'Family Name',
'Nationality' => 'Nationality'
),
'getCMSFields_forPopup'
);
$tablefield->setAddTitle( 'A Student' );
$fields->addFieldToTab( 'Root.Content.Students', $tablefield );
return $fields;
}
}
class Mentor_Controller extends Page_Controller {
}
?>
Student.php:
-------------
<?php
class Student extends DataObject {
public static $db = array(
'FirstName' => 'Text',
'LastName' => 'Text',
'Nationality' => 'Text'
);
static $has_one = array (
'MyMentor' => 'Mentor'
);
function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push( new TextField( 'FirstName', 'First Name' ));
$fields->push( new TextField( 'LastName', 'Last Name' ));
$fields->push( new TextField( 'Nationality', 'Nationality' ));
return $fields;
}
}
?>
Regards
PeeJay