Good morning,
I am having trouble with $hasMany, even though $hasOne works fine.
I have two models, Assignment and AssignmentGroup. Assignment can have one AssignmentGroup but AssignmentGroup can have many Assignments. Here are the relationships:
class Assignment extends AppModel {
public $belongsTo = array('AssignmentGroup');
}
class AssignmentGroup extends AppModel {
public $hasMany = array(
'Assignment' => array('foreignKey'=>'assignment_group_id),
);
}
Here's the code I'm running:
$this->AssignmentGroup->Behaviors->load('Containable');
$params = array(
'conditions' => array('AssignmentGroup.class_id' => $class_id),
'contain' => array('Assignment'),
);
$result = $this->AssignmentGroup->find('all', $params);
When I use $hasOne instead of $hasMany I get the expected result.
$result = array(
'AssignmentGroup => array(
[several elements]
),
'Assignment' => array(
[more elements]
),
);
However, when I use $hasMany, as I need to, things fall apart. The query does not have a JOIN.
$result = array(
'AssignmentGroup => array(
[several elements]
),
'Assignment' => array(),
);
Can anyone explain what's going on and/or suggest a solution? Thanks for the help.