# Problems with associations

**URL:** <https://discourse.cakephp.org/t/problems-with-associations/4119>\
**Category:** Need Help\
**Created:** [March 30, 2018, 5:21pm UTC](https://discourse.cakephp.org/t/problems-with-associations/4119 "2018-03-30T17:21:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbratcher](https://avatars.discourse-cdn.com/v4/letter/j/839c29/32.png) [@jbratcher](https://discourse.cakephp.org/u/jbratcher)\
**Post date:** [March 30, 2018, 5:21pm UTC](https://discourse.cakephp.org/t/problems-with-associations/4119/1 "2018-03-30T17:21:14Z")

</div>

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?
