Hi all,
I am working on a CakePHP app where people can view and sign up for
classes (or 'meetings', as i have called them. That was the best
synonym i could think up for the reserved word of 'class').
Unfortunately, i can't change the existing database structure, so i am
trying my best to work with it. One issue i am currently having is
that the join table which houses student ids and class ids also has
other info, such as status (whether they have attended, enrolled,
dropped, etc). I've researched this a bit on this group and realize
that i can't really use the HABTM relationship because of these extra
fields. Instead, i am working on using hasMany and belongsTo.
I have reached a dead end though. Here is the stripped down set up.
------Tables-------
CREATE TABLE `tbltrainees` (
`TraineeID` varchar(11) NOT NULL,
`FirstName` varchar(30) default NULL,
`MiddleName` varchar(20) default NULL,
`LastName` varchar(30) default NULL,
PRIMARY KEY (`TraineeID`),
);
CREATE TABLE `tblclasses` (
`ClassID` varchar(15) NOT NULL,
`ClassTitle` varchar(50) default NULL,
PRIMARY KEY (`ClassID`),
) ;
CREATE TABLE `tbltraineesclasses` (
`ID` int(6) NOT NULL auto_increment,
`ClassID` varchar(50) NOT NULL,
`TraineeID` varchar(50) NOT NULL,
`TraineeStatus` int(10) NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `ClassID_2` (`ClassID`,`TraineeID`),
) ;
-------Models-------
class Trainee extends AppModel
{
var $name = 'Trainee';
var $tablePrefix = 'tbl';
var $primaryKey = 'TraineeID';
var $hasMany = array(
'Enrollment'=>array('className'=>'Enrollment','foreignKey'=>'TraineeID')
);
}
class Meeting extends AppModel
{
var $name = 'Meeting';
var $useTable = 'tblclasses';
var $primaryKey = 'ClassID';
var $belongsTo = array(
'Room'=>array('className'=>'Room','foreignKey'=>'RoomID'),
'Course'=>array('className' => 'Course','foreignKey'
=> 'CourseID'),
);
var $hasMany = array(
'Enrollment'=>array('className'=>'Enrollment','foreignKey'=>'ClassID')
);
}
class Enrollment extends AppModel
{
var $name = 'Enrollment';
var $useTable = 'tbltraineesclasses';
var $primaryKey = 'ID';
var $belongsTo = array(
'Trainee' =>
array('className'=>'Trainee','foreignKey'=>'TraineeID'),
'Meeting' =>
array('className'=>'Meeting','foreignKey'=>'ClassID'),
'TraineeStatus' =>
array('className'=>'TraineeStatus','foreignKey'=>'StatusID')
);
}
(i haven't included the trainee status,room and course table info/
models for sake of brevity)
My issue is that when i look at '/trainees/view/1234', there are two
queries performed - the select for the Trainee, and the related select
for the Enrollment records for that Trainee ID. I can't seem to then
get the related Meeting data for each of those Enrollments. Also, the
related TraineeStatus records are not returned either.
Is there something obvious i am doing wrong here?
On a larger note, is there a better way to do all of this? I just saw
something about using a finderQuery instead. Should I try that?
thanks!
-dave
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---