{JA} - 3.7.8.6 recursive

recursive プロパティは、CakePHP が find()findAll() メソッドを通しても関連するモデルデータをどの階層まで取得するかを定義します。

アプリケーションがあるドメインに属している Group をもち、Groupが多くの User をもち、同様に User が多くの Article を持っているとします。$this->Group->find() を呼び出して返してほしいデータ量に基づいて、$recursive に異なる値を設定することができます:

深さ詳細
-1Cake は Group データだけを取得します。join しません。
0Cake は Group データとそのドメインを取得します。
1Cake は1つの Group とそのドメインとそれに関連した User を取得します。
2Cake は1つの Group とそのドメインとそれに関連した User と各 User に関連した Article を取得します。

必要以上に高く設定しないでください。CakePHP がデータを取得する際に、不必要にアプリケーションを遅くしたくないでしょう。

機能的に $recursive を fields と結合したい場合、手動で fields 配列に必要な外部キーを含むカラムを追加しなければなりません。上記の例では、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

Lines: 1-12Lines: 1-12
 <title>recursive</title> <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-&gt;Group-&gt;find() call:</p>
+<p>recursive プロパティは、CakePHP <code>find()</code> <code>findAll()</code> メソッドを通しても関連するモデルデータをどの階層まで取得するかを定義します。</p>
<p>アプリケーションがあるドメインに属している Group をもち、Groupが多くの User をもち、同様に User が多くの Article を持っているとします。$this-&gt;Group-&gt;find() を呼び出して返してほしいデータ量に基づいて、$recursive に異なる値を設定することができます:</p>
 <table> <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>
+<tr><th>深さ</th><th>詳細</th></tr>
<tr><td>-1</td><td>Cake Group データだけを取得します。join しません。</td></tr>
<tr><td>0</td><td>Cake Group データとそのドメインを取得します。</td></tr>
<tr><td>1</td><td>Cake は1つの Group とそのドメインとそれに関連した User を取得します。</td></tr>
<tr><td>2</td><td>Cake は1つの Group とそのドメインとそれに関連した User と各 User に関連した Article を取得します。</td></tr>
 </table> </table>
-<p>Set it no higher than you need. Having CakePHP fetch data you arent 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>
+<p>必要以上に高く設定しないでください。CakePHP がデータを取得する際に不必要にアプリケーションを遅くしたくないでしょう。</p>
<p class="note">機能的に $recursive <code>fields</code> と結合したい場合、手動で <code>fields</code> 配列に必要な外部キーを含むカラムを追加しなければなりません。上記の例では、<code>domain_id</code> を追加することになります。</p>