How to get data in level 2/3 ( same like cakephp 2.x recursive ) in cakephp 4.x

As we know recursive has been removed from cakePHP 4.x but how to get data in 2-3 level ?

I have those tables
countries ( data of all countries )
users ( have country_id field )
applications ( have user_id field )

In Model > Table
ApplicationsTable have $this->belongsTo(‘Users’);
UsersTable have $this->belongsTo(‘Countries’);

Now in Controller

$this->paginate = [‘contain’ => [‘Users’],
‘limit’ => 100, ‘conditions’ => [‘Applications.project_id’ => $id], ‘order’ => [‘id’ => ‘desc’]];
$data = $this->paginate($this->Applications->find(‘all’));

now i have resultSet like

[0] => (
applicaiton table data
[user] => (
users data …
)
)

but i need country data under user (that we can do in cakephp 2 using recursive level 2 )

[0] => (
applicaiton table data …
[users] => (
users data …
[country] (
country data here …

                  )
      
      )

)

Thanks

Did you read the documentation on containment?

‘contain’ => [‘Users’ => ['Countries']]

1 Like