{EN} - 3.7.8.6 recursive

The recursive property defines how deep CakePHP should go to fetch associated model data via find(), findAll() and read() methods.

Imagine your application features Groups which belong to a domain and have many Users which in turn have many Articles. You can set $recursive to different values based on the amount of data you want back from a $this->Group->find() call:

DepthDescription
-1Cake fetches Group data only, no joins.
0Cake fetches Group data and its domain
1Cake fetches a Group, its domain and its associated Users
2Cake fetches a Group, its domain, its associated Users, and the Users' associated Articles

Set it no higher than you need. Having CakePHP fetch data you aren’t going to use slows your app unnecessarily.

If you want to combine $recursive with the fields functionality, you will have to add the columns containing the required foreign keys to the fields array manually. In the example above, this could mean adding domain_id.

{EN} - 3.7.8.6 recursive

The recursive property defines how deep CakePHP should go to fetch associated model data via find(), findAll() and read() methods.

Imagine your application features Groups which belong to a domain and have many Users which in turn have many Articles. You can set $recursive to different values based on the amount of data you want back from a $this->Group->find() call:

DepthDescription
-1Cake fetches Group data only, no joins.
0Cake fetches Group data and its domain
1Cake fetches a Group, its domain and its associated Users
2Cake fetches a Group, its domain, its associated Users, and the Users' associated Articles

Set it no higher than you need. Having CakePHP fetch data you aren’t going to use slows your app unnecessarily.

If you want to combine $recursive with the fields functionality, you will have to add the columns containing the required foreign keys to the fields array manually. In the example above, this could mean adding domain_id.

Differences