Hi All,
I'm building a CakePHP app for tracking clinic patients, their visits,
their symptoms and questionnaire answers. The barrier I've encountered
is that each patient has many visits AND many symptoms. I want to view
the patient record and their aggregate visits and symptoms.
I've defined a hasMany relationship in the patient model as such:
var $hasMany = array(
'Visit' => array(
'order' => 'Visit.id DESC',
'limit' => '10'
),
'M5Symptom' => array(
'className' => 'M5Symptom',
'order' => 'M5Symptom.modified DESC',
'limit' => '25'
)
);
In the patient view I get the relevant patient data, and the
corresponding list of visits, but I get the message, "Undefined
index: M5Symptom" for listing the symptoms. As far as I can tell the
model is correct, because the query for the patient view finds and
retrieves a list of 25 symptom records exactly as specified in the
model. From that I take that the model and controller must be working
as expected. Otherwise the query wouldn't be right and/or it wouldn't
retrieve the pertinent records. The query that results is EXACTLY what
I want.
That leads me to believe the problem must be in the view.
Here's the view function in the patient controller:
function view($id = null) {
$this->Patient->id = $id;
$this->set('patient', $this->Patient->read());
}
Everything works right up until I try to list the symptoms. Here's the
code for listing symptoms in the view:
echo $html->tableHeaders(array('Symptom','Start Date','End Date',
'Severity'));
foreach ($patient['M5Symptom'] as $symptom) {
echo $html->tableCells(
array($symptom['symptom'],
$symptom['start_date'],
$symptom['end_date'],
$symptom['severity'],
)
);
}
I've looked at all of this over and over and I just can't find out why
'M5Symptom' is undefined. Just above this, 'Visit' lists recent visit
dates for me with the exact same logic in place.
Am I wrong in assuming I can define more than one hasMany? If so, why
is the correct query generated? I'm hoping another set of eyes will
find what I'm missing. Sleeping on it didn't help.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---