質問編集履歴
2
変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
cakephp3で他テーブル
|
1
|
+
cakephp3で結合後、他テーブルのカラムの条件で取得したい
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
-
他テーブルと結合して、取得条件を設定したい。
|
3
|
+
他テーブルと結合して、他テーブルのカラムで取得条件を設定したい。
|
4
4
|
|
5
5
|
公式ドキュメントを見ているのですが、containとinnserjoinの使い方がいまいちよくわかっていません。
|
6
6
|
|
@@ -46,30 +46,18 @@
|
|
46
46
|
|
47
47
|
//ArticlesController.php
|
48
48
|
|
49
|
-
//
|
49
|
+
//userのロール条件で取得
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
$articles = $this->Articles->find('all'
|
51
|
+
$articles = $this->Articles->find('all')->contain(['users','colors'])->where(['role' => 1]);
|
54
52
|
|
55
53
|
$this->set('articles', $articles);
|
56
54
|
|
57
|
-
debug($articles);
|
58
55
|
|
59
|
-
|
60
|
-
|
61
|
-
//userのロール条件で取得
|
62
|
-
|
63
|
-
$articles = $this->Articles->find('all',contain =>['users','colors'])->where(['role' => 1]);
|
64
|
-
|
65
|
-
$this->set('articles', $articles);
|
66
|
-
|
67
|
-
debug($articles);
|
68
56
|
|
69
57
|
|
70
58
|
|
71
59
|
```
|
72
60
|
|
61
|
+
これをすると、Error: Call to undefined method App\Controller\ArticlesController::where() と出ます。
|
73
62
|
|
74
|
-
|
75
|
-
|
63
|
+
なぜwhereが使えなくなってしまったのでしょうか。
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,7 +60,7 @@
|
|
60
60
|
|
61
61
|
//userのロール条件で取得
|
62
62
|
|
63
|
-
$this->Articles->find('all',contain =>['users','colors'])->where(['role' => 1]);
|
63
|
+
$articles = $this->Articles->find('all',contain =>['users','colors'])->where(['role' => 1]);
|
64
64
|
|
65
65
|
$this->set('articles', $articles);
|
66
66
|
|