I am having problems accessing data in a join table. I have searched
and read and searched some more, but am still a bit befuddled. At
first I used the 'with' condition on the HABTM association, and it
worked somewhat nicely.
What i had:
class Trainee extends AppModel
{
var $name = 'Trainee';
var $tablePrefix = 'tbl';
var $primaryKey = 'TraineeID';
var $hasAndBelongsToMany = array(
'Meeting'=>array(
'className'=>'Meeting',
'joinTable'=>'tbltraineesclasses',
'with'=>'Enrollment',
'foreignKey'=>'TraineeID',
'associationForeignKey'=>'ClassID',
'unique'=>true
));
}
class Meeting extends AppModel
{
var $name = 'Meeting';
var $useTable = 'tblclasses';
var $primaryKey = 'ClassID';
var $hasAndBelongsToMany = array(
'Trainee'=>array(
'className'=>'Trainee',
'joinTable'=>'tbltraineesclasses',
'with'=>'Enrollment',
'foreignKey'=>'ClassID',
'associationForeignKey'=>'TraineeID',
'unique'=>true
));
}
class Enrollment extends AppModel
{
var $name = 'Enrollment';
var $useTable = 'tbltraineesclasses';
var $primaryKey = 'ID';
var $belongsTo = array(
'TStatus' => array(
'className'=>'TStatus',
'foreignKey'=>'TraineeStatus'),
);
}
When viewing a Trainee with things set up this way, I got:
SELECT `Trainee`.stuff
FROM `tbltrainees` AS `Trainee` WHERE `Trainee`.`TraineeID` = 1234
LIMIT 1
SELECT `Meeting`.stuff, `Enrollment`.stuff
FROM `tblclasses` AS `Meeting` JOIN `tbltraineesclasses` AS
`Enrollment` ON (`Enrollment`.`TraineeID` = '1234' AND
`Enrollment`.`ClassID` = `Meeting`.`ClassID`)
The one issue i could not figure out was that the query was not
joining on the TStatus model (i had the complimenting $hasMany
variable set in the TStatus model as well).
I then played around with this set up by removing the 'with'
condition, as I have read in a couple places that this is no longer
needed in 1.2. After I did this, the Trainee and Meeting tables were
joined via the join table, but none of the data from that table was
returned. In the Trainees controller i tried calling a $this-
>set('enrollments',$this->Trainee->MeetingsTrainees->findAll()) but
that bombed out on the 'MeetingsTrainees' part.
I feel like i've been running in circles a bit, and would appreciate
any insight anyone may have.
thanks!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---