Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ja/orm/behaviors/tree.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ CakePHP は内部構造を構築することができます。 ::
echo $category->name . "\n";
}

条件を渡す必要がある場合は、通常通り::

$descendants = $categories
->find('children', ['for' => 1])
->where(['name LIKE' => '%Foo%']);

foreach ($descendants as $category) {
echo $category->name . "\n";
}

代わりに、各ノードの子が階層内にネストされているスレッドリストが必要な場合は、
'threaded' ファインダを積み重ねられます。 ::

Expand Down
2 changes: 1 addition & 1 deletion ja/orm/database-basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Select 文の実行
$results = $connection
->execute(
'SELECT * FROM articles WHERE created >= :created',
['created' => DateTime('1 day ago')],
['created' => new DateTime('1 day ago')],
['created' => 'datetime']
)
->fetchAll('assoc');
Expand Down
39 changes: 0 additions & 39 deletions ja/orm/saving-data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,45 +101,6 @@ CakePHP は挿入または更新のいずれの処理を行うかを ``isNew()``

$articlesTable->Tags->link($article, [$tag1, $tag2]);

結合用テーブルへのデータ保存
----------------------------

結合用テーブルへのデータ保存は、特別な ``_joinData`` プロパティーを使用して行われます。
このプロパティーは結合用の Table クラスの ``Entity`` インスタンスになっているはずです。 ::

// 最初にレコードを紐付けます。
$tag1 = $articlesTable->Tags->findByName('cakephp')->first();
$tag1->_joinData = $articlesTable->ArticlesTags->newEntity();
$tag1->_joinData->tagComment = 'CakePHP の ORM は実に強力です!';

$articlesTable->Tags->link($article, [$tag1]);

// 既存のアソシエーションを更新します。
$article = $articlesTable->get(1, ['contain' => ['Tags']]);
$article->tags[0]->_joinData->tagComment = '新しいコメント。'

// 必須です。なぜならプロパティーを直接変更しているからです。
$article->dirty('tags', true);

$articlesTable->save($article, ['associated' => ['Tags']]);

``newEntity()`` や ``patchEntity()`` を使う時に、結合用テーブルの情報もまた
作成/更新することができます。 POST データはこうなります。 ::

$data = [
'title' => '私の素晴らしいブログ投稿',
'body' => '何かのコンテンツが少し続きます。',
'tags' => [
[
'id' => 10,
'_joinData' => [
'tagComment' => '素晴らしい記事です!',
]
],
]
];
$articlesTable->newEntity($data, ['associated' => ['Tags']]);

多対多レコードの紐付け解除
--------------------------

Expand Down