{1449} - 3.7.8.6 $recursive

An integer specifying the number of levels you wish CakePHP to fetch associated model data in find() and findAll() operations.

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:

  • -1 - Cake fetches Group data only, no joins.
  • 0 - Cake fetches Group data and its domain
  • 1 - Cake fetches a Group, its domain and its associated Users
  • 2 - Cake 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 unnecessarily slows your app.

{5584} - 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

Lines: 1-10Lines: 1-12
-<title>$recursive</title>
<p>An integer specifying the number of levels you wish CakePHP to fetch associated model data in find() and findAll() operations.</p>
+<title>recursive</title>
<p>The recursive property defines how deep CakePHP should go to fetch associated model data via <code>find()</code>, <code>findAll()</code> and <code>read()&lt;/code> methods.</p>
 <p>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-&gt;Group-&gt;find() call:</p> <p>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-&gt;Group-&gt;find() call:</p>
-<ul>
<li>-1 - Cake fetches Group data only, no joins.</li>
<li>0 - Cake fetches Group data and its domain</li>
<li>1 - Cake fetches a Group, its domain and its associated Users</li>
<li>2 - Cake fetches a Group, its domain, its associated Users, and the Users' associated Articles</li>
</ul>
<p>Set it no higher than you need–having CakePHP fetch data you aren’t going to use unnecessarily slows your app.</p>
+<table>
<tr>&lt;th>Depth</th><th>Description</th></tr> /><tr><td>-1</td><td>Cake fetches Group data only, no joins.</td>&lt;/tr>
<tr>&lt;td>0</td><td>Cake fetches Group data and its domain</td>&lt;/tr>
<tr>&lt;td>1</td><td>Cake fetches a Group, its domain and its associated Users</td>&lt;/tr>
<tr>&lt;td>2</td><td>Cake fetches a Group, its domain, its associated Users, and the Users' associated Articles</td>&lt;/tr>
</table>
<p>Set it no higher than you need. Having CakePHP fetch data you aren’t going to use slows your app unnecessarily.</p> />&lt;p class=&quot;note">If you want to combine $recursive with the <code>fields</code> functionality, you will have to add the columns containing the required foreign keys to the <code>fields</code> array manually. In the example above, this could mean adding <code>domain_id</code>.</p>