回答編集履歴
1
コードを追加
test
CHANGED
@@ -3,3 +3,53 @@
|
|
3
3
|
[https://book.cakephp.org/2.0/ja/models/retrieving-your-data.html#id6](https://book.cakephp.org/2.0/ja/models/retrieving-your-data.html#id6)
|
4
4
|
|
5
5
|
これを応用できそうですね。
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
```php
|
10
|
+
|
11
|
+
$db = $this->UsersInterview->getDataSource();
|
12
|
+
|
13
|
+
$subQuery = $db->buildStatement(
|
14
|
+
|
15
|
+
array(
|
16
|
+
|
17
|
+
'fields' => array('"UI2"."id"'),
|
18
|
+
|
19
|
+
'table' => $db->fullTableName($this->UsersInterview),
|
20
|
+
|
21
|
+
'alias' => 'UI2',
|
22
|
+
|
23
|
+
'limit' => null,
|
24
|
+
|
25
|
+
'offset' => null,
|
26
|
+
|
27
|
+
'joins' => array(),
|
28
|
+
|
29
|
+
'conditions' => 'UsersInterview.user_id = UI2.user_id AND UsersInterview.created < UI2.created',
|
30
|
+
|
31
|
+
'order' => null,
|
32
|
+
|
33
|
+
'group' => null
|
34
|
+
|
35
|
+
),
|
36
|
+
|
37
|
+
$this->UsersInterview
|
38
|
+
|
39
|
+
);
|
40
|
+
|
41
|
+
$subQuery = 'NOT EXISTS (' . $subQuery . ') ';
|
42
|
+
|
43
|
+
$subQueryExpression = $db->expression($subQuery);
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
$conditions[] = $subQueryExpression;
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
$this->UsersInterview->find('all', compact('conditions'));
|
52
|
+
|
53
|
+
```こんなんで出来るのかな・・・
|
54
|
+
|
55
|
+
これだったら、SQLを直接書いた方が優しい感じがします。
|