# Join with 3 tables doesn't put the belongsTo relation in cakephp 2.5.6

**URL:** <https://discourse.cakephp.org/t/join-with-3-tables-doesnt-put-the-belongsto-relation-in-cakephp-2-5-6/7910>\
**Category:** Need Help\
**Created:** [June 6, 2020, 6:43pm UTC](https://discourse.cakephp.org/t/join-with-3-tables-doesnt-put-the-belongsto-relation-in-cakephp-2-5-6/7910 "2020-06-06T18:43:02Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![mdeanquin](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mdeanquin/32/1802_2.png) [@mdeanquin](https://discourse.cakephp.org/u/mdeanquin)\
**Post date:** [June 15, 2020, 6:50pm UTC](https://discourse.cakephp.org/t/join-with-3-tables-doesnt-put-the-belongsto-relation-in-cakephp-2-5-6/7910/2 "2020-06-15T18:50:21Z")

</div>

When I put recursive = 2 to retrieve the data from all the tables it gives me this error:

 ![error_recursive_2](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/3/3ffecd0a270b5007086a7a51b87ad9ea77d87730.png)  
It seems that when I put recursive = 2 the User model only retrieves the belongsto relation and not the hasmany, this is the code of model User:

```auto
<?php
     App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth');
     class User extends AppModel {
         var $name = 'User';

         public $virtualFields = array(
            'full_name' => "CONCAT(User.firstname, ' ',User.lastname)"
        );
         
        public $displayField = 'full_name';

        public $order = array('User.profile_id', 'User.lastname');
         
        public $belongsTo = array(
            'Profile' => array(
                'className' => 'Profile'
            ),
            'Referrer' => array(
                'className' => 'User',
                'foreignKey' => 'referrer_id'
            )
        );

        public $hasMany = array(
            'Pacient' => array(
                'className' => 'Pacient'
            ),
            'UserxGroup' => array(
                'className' => 'UserxGroup',
                'foreignKey' => 'user_id'
            )
        );

         public function beforeSave($options = array()) {
             if (isset($this->data[$this->alias]['password'])) {
                 $passwordHasher = new BlowfishPasswordHasher();
                 $this->data[$this->alias]['password'] = $passwordHasher->hash(
                 $this->data[$this->alias]['password']
                 );
             }
             return true;
         }

         var $actsAs = array(
            'UploadPack.Upload' => array(
                'image' => array(
                    'styles' => array(
                        'thumb' => '200x200',
                        'detail' => '512x512'
                    )
                )
            )
        );
     }
?>

```

What should I do to have the hasmany relations included in the query?

---

_[View the full topic](https://discourse.cakephp.org/t/join-with-3-tables-doesnt-put-the-belongsto-relation-in-cakephp-2-5-6/7910)._
