So, I’m having a problem with getting associations to connect correctly.
For example,
In the StudentsTable I have
$this->belongsToMany(‘Users’, [
‘through’ => ‘StudentsUsers’,
‘sort’ => ‘l_name ASC, f_name ASC’
]);
$this->belongsToMany(‘CaseManagers’, [
‘className’ => ‘Users’,
‘through’ => ‘StudentsUsers’,
‘foreignKey’ => ‘student_id’,
‘targetForeignKey’ => ‘user_id’,
‘conditions’ => ‘StudentsUsers.relationship = 25’
]);
In the UsersTable I have:
$this->hasOne(‘Persons’);
So, the problem occurs when I try to get the Person association on the CaseManagers.
$students = $this->Students->find()->contain([‘Users’ => [‘Persons’], ‘CaseMangers’ => [‘Persons’]]);
Since CaseManagers is still a User it should be able to contain the Person data as well. But cake tries to look at Person.case_manager_id for some reason instead of looking at user_id like it should. Am I missing a setting somewhere?