table: graduate_applicants
CREATE TABLE IF NOT EXISTS `graduate_applicants` (
`grat_id` int(10) NOT NULL auto_increment,
`studentnum` int(9) NOT NULL,
`QuarterID` int(10) NOT NULL,
PRIMARY KEY (`grat_id`)
)
table: stu_students
CREATE TABLE IF NOT EXISTS `stu_students` (
`id` int(11) NOT NULL auto_increment,
`studentid` int(9) default NULL,
`firstname` varchar(50) default NULL,
`lastname` varchar(50) default NULL,
`email` varchar(100) default NULL,
PRIMARY KEY (`id`),
KEY `studentid` (`studentid`),
)
model:
class GraduateApplicant extends AppModel{
var $name = 'GraduateApplicant';
var $tablePrefix = '';
var $belongsTo = array('Student' => array('className' => 'Student','foreignKey' => false,''conditions' => array('Student.studentid=GraduateApplicant.studentnum'),'fields' => '','order' => ''),);
}
controller:
$list = $this->paginate('GraduateApplicant');
i can not understand why $list is empty ?
CakePHP really makes your life easier if you set up your tables to properly reflect the relationships between them. You could cut your code down by 90% because you don’t have to try to manually specify the way the tables are linked.
Then your model would be simple:
If it’s an option, I would recommend setting up your database tables properly like this, instead of having the student ID columns called different things in different tables (
Student.studentid,GraduateApplicant.studentnum)And it will also make your life a lot easier if you name your models to properly reflect your table names. Your table is called
stu_studentsbut your model is calledStudent. You should either name your tablestudentsand your modelStudent, your tablestu_studentsand your modelStuStudent.