質問編集履歴

1

現状の追記

2019/02/11 05:17

投稿

art_of
art_of

スコア21

test CHANGED
File without changes
test CHANGED
@@ -105,3 +105,59 @@
105
105
  ------------------------------------------------------------------------
106
106
 
107
107
  ```
108
+
109
+
110
+
111
+ ### 現状
112
+
113
+
114
+
115
+ 現状以下のようになっています。
116
+
117
+ ```
118
+
119
+ $this->Post->find('all',array(
120
+
121
+ 'fields' => array(
122
+
123
+ ' (select count(*) from posts where user_id=t1.user_id and type=2) as cnt
124
+
125
+ , t1.*'
126
+
127
+ ),
128
+
129
+ 'conditions' => array(
130
+
131
+ 'type' => 0
132
+
133
+ )
134
+
135
+ 'order' => array(
136
+
137
+ '1 desc'
138
+
139
+ )
140
+
141
+ ))
142
+
143
+ ```
144
+
145
+ 以下のSQL文が発行されます
146
+
147
+ ```
148
+
149
+ select (select count(*) from posts where user_id=t1.user_id and type=2) as cnt
150
+
151
+ , t1.*
152
+
153
+ from posts
154
+
155
+ where type=0
156
+
157
+ order by 1 desc
158
+
159
+ ```
160
+
161
+ 当然、from posts t1とはなりません。
162
+
163
+ 何か解決方法はあるでしょうか。