質問編集履歴
2
追加対応時のエラーを追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -203,3 +203,35 @@
|
|
203
203
|
|
204
204
|
|
205
205
|
よろしくお願いいたします。
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
2020/09/25 追記
|
210
|
+
|
211
|
+
回答に記載いただいた[こちらの記事](https://qiita.com/ayies128/items/2c5596eef388ef92291b)を参考にコントローラー内の処理を変更したところ、発行されたSQL文に関するエラーが表示されました。
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
【変更内容】
|
216
|
+
|
217
|
+
```ここに言語を入力
|
218
|
+
|
219
|
+
def index
|
220
|
+
|
221
|
+
@q = User.joins(orders: :order_racket_infos).select("users.id, name, count(orders.id) as orders, sum(orders.amount) as total_amount, count(order_racket_infos.id), users.created_at, kit_shipped_date").where(del_flg: 1).where(orders: { order_completed: true }).ransack(params[:q])
|
222
|
+
|
223
|
+
@users = @q.result(distinct: true).order("users.created_at DESC")
|
224
|
+
|
225
|
+
end
|
226
|
+
|
227
|
+
```
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
【表示されたエラー】
|
232
|
+
|
233
|
+
```ここに言語を入力
|
234
|
+
|
235
|
+
Mysql2::Error: In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'gappari_api2_development.users.id'; this is incompatible with sql_mode=only_full_group_by
|
236
|
+
|
237
|
+
```
|
1
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -78,7 +78,7 @@
|
|
78
78
|
|
79
79
|
def index
|
80
80
|
|
81
|
-
@q = User.where(del_flg: 1).includes(orders: :order_
|
81
|
+
@q = User.where(del_flg: 1).includes(orders: :order_items).ransack(params[:q])
|
82
82
|
|
83
83
|
@users = @q.result(distinct: true).order("created_at DESC")
|
84
84
|
|
@@ -136,7 +136,7 @@
|
|
136
136
|
|
137
137
|
<% orders = user.orders.where(order_completed: true) %>
|
138
138
|
|
139
|
-
<% total_
|
139
|
+
<% total_items = 0 %>
|
140
140
|
|
141
141
|
<% amounts = 0 %>
|
142
142
|
|
@@ -144,9 +144,9 @@
|
|
144
144
|
|
145
145
|
<%# 累計本数を取得 %>
|
146
146
|
|
147
|
-
<% order_
|
147
|
+
<% order_items = order.order_items.count %>
|
148
|
-
|
148
|
+
|
149
|
-
<% total_
|
149
|
+
<% total_items += order_items %>
|
150
150
|
|
151
151
|
<%# 累計金額を取得 %>
|
152
152
|
|
@@ -178,7 +178,7 @@
|
|
178
178
|
|
179
179
|
</td>
|
180
180
|
|
181
|
-
<td class="align-middle"><%= total_
|
181
|
+
<td class="align-middle"><%= total_items.to_s(:delimited) %>本</td>
|
182
182
|
|
183
183
|
<td class="align-middle text-right"><%= amounts.to_s(:delimited) %>円</td>
|
184
184
|
|