{2132} - 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.
Note: if you want to combine $recursive with the 'fields' functionality described later on, 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'.
{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:
| Depth | Description |
|---|---|
| -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 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-11 | Lines: 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()</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->Group->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->Group->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> <p><em>Note:</em> if you want to combine $recursive with the 'fields' functionality described later on, 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'.</p> |
+ | <table> <tr><th>Depth</th><th>Description</th></tr> /><tr><td>-1</td><td>Cake fetches Group data only, no joins.</td></tr> <tr><td>0</td><td>Cake fetches Group data and its domain</td></tr> <tr><td>1</td><td>Cake fetches a Group, its domain and its associated Users</td></tr> <tr><td>2</td><td>Cake fetches a Group, its domain, its associated Users, and the Users' associated Articles</td></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> <p class="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> |
